事件传参
<p><strong>事件传参</strong></p>
<hr />
<ul>
<li>默认参数e,e.target 相当于获取DOM</li>
</ul>
<pre><code class="language-javascript">&lt;template&gt;
&lt;button ref=&quot;btn&quot; @click=&quot;clickButton&quot;&gt;点击&lt;/button&gt;
&lt;/template&gt;
const btn = ref(null)
const clickButton = (e) =&gt; {
console.log(e.target == btn.value) // true
console.log(e.target.innerHTML) // 点击
}</code></pre>
<hr />
<ul>
<li>普通参数</li>
</ul>
<pre><code class="language-javascript">&lt;template&gt;
&lt;div @click=&quot;clickDiv(item.name)&quot; v-for=&quot;item in itemList&quot;&gt;{{ item.name }}&lt;/div&gt;
&lt;/template&gt;
let itemList = [{ name: &quot;Andy&quot; }, { name: &quot;Bruce&quot; }, { name: &quot;Curry&quot; }]
const clickDiv = (item) =&gt; {
console.log(item)
}</code></pre>
<hr />
<ul>
<li>事件中已经有自定义参数了,如何获取默认参数e呢?</li>
</ul>
<pre><code class="language-javascript">&lt;template&gt;
&lt;div @click=&quot;clickDiv(item.name, $event)&quot; v-for=&quot;item in itemList&quot;&gt;{{ item.name }}&lt;/div&gt;
&lt;/template&gt;
let itemList = [{ name: &quot;Andy&quot; }, { name: &quot;Bruce&quot; }, { name: &quot;Curry&quot; }]
const clickDiv = (item, e) =&gt; {
console.log(item)
console.log(e)
}</code></pre>