new Vue( {
el: "#search",
data () {
return {
s: '',
show: false
}
},
methods: {
search: function () {
console.log('search')
},
hotSearch: function (event) {
console.log('hot search')
this.show = false
}
}
})

<div id="search">
<div class='search-bar'>
<span>
<input type="text" v-model.trim="s" @keyup.enter="search"
@focus="show=true" @blur="show=false" placeholder="search...">
</span>
<a @click='search'><span>search</span></a>
<div v-show="show" id="drop-down-list">
<em></em>
<dl class="content">
<dt>热门搜索:</dt>
<dd @click="hotSearch">CoolPlay</dd>
<dd @click="hotSearch">sky fall</dd>
<dd @click="hotSearch">no man's sky</dd>
<dd @click="hotSearch">dota2</dd>
<dd @click="hotSearch">something</dd>
</dl>
</div>
</div>
</div>
&#13;
当我犯下&#34;搜索&#34; (<a @click='search'><span>search</span></a>
),函数search
有效。
当我关注输入并点击dd
元素(例如<dd @click="hotSearch">CoolPlay</dd>
)时,函数hotSearch
无法正常工作。但是,当我将<div v-show="show" id="drop-down-list">
更改为<div v-show="true" id="drop-down-list">
时,函数hotSearch
可以正常工作。
请告诉我哪里出错了以及如何解决。谢谢。