使用VueJS重置Select2组件

时间:2018-10-31 15:08:18

标签: vuejs2

我仍在学习VueJS并感到困惑。 example here包含Select2的基本组件(来自其网站)

<div id="el"></div>

<!-- using string template here to work around HTML <option> placement restriction -->
<script type="text/x-template" id="demo-template">
  <div>
    <p>Selected: {{ selected }}</p>
    <select2 :options="options" v-model="selected">
      <option disabled value="0">Select one</option>
    </select2>
  </div>
</script>

<script type="text/x-template" id="select2-template">
  <select>
    <slot></slot>
  </select>
</script>

我试图添加一个按钮以将组件重置为其初始状态。我使用了Select2,但是不能使用在Stackoverflow上找到的解决方案,因为它们依赖于jQuery。我真的很感谢从哪里开始的任何线索

1 个答案:

答案 0 :(得分:0)

您的初始状态是什么?如果是2,则使用此:

<button @click="selected = 2">Reset</button>