vue2:当我使用' v-show'时,@ click没有效果

时间:2017-03-31 01:39:17

标签: javascript vue.js vuejs2

Here's a link to my JSFiddle



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;
&#13;
&#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可以正常工作。

请告诉我哪里出错了以及如何解决。谢谢。

0 个答案:

没有答案