javascript - 无法从 VueJS 监听 Bootstrap 按钮组内的点击事件

标签 javascript twitter-bootstrap vue.js

我在基于 VueJS 的项目中有以下 Bootstrap 按钮组...

<div class="btn-group btn-group-xs pull-right" data-toggle="buttons">
  <label class="btn btn-primary label-primary">
	<input type="radio" name="options" id="option1" autocomplete="off" v-on:click="clearEntries"> A
  </label>
  <label class="btn btn-primary label-primary">
	<input type="radio" name="options" id="option2" autocomplete="off" v-on:click="clearEntries"> B
  </label>
  <label class="btn btn-primary active label-primary">
	<input type="radio" name="options" id="option3" autocomplete="off" checked v-on:click="clearEntries"> C
  </label>
   <label class="btn btn-primary label-primary">
	<input type="radio" name="options" id="option4" autocomplete="off" v-on:click="clearEntries"> D
  </label>
</div>

我想要做的就是在选择/选中其中一个单选按钮时调用一个方法。

但是点击事件永远不会被触发。我不确定它是否被 bootstrap css 抑制了。

有什么想法吗?

最佳答案

v-on:click="clearEntries" 放在标签上,而不是输入上。

new Vue({
  el: "#app",
  methods: {
    clearEntries: function() {
      alert('clearEntries !');
    }
  }
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.5/vue.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<div id="app">
<div class="btn-group btn-group-xs pull-right" data-toggle="buttons">
  <label v-on:click="clearEntries" class="btn btn-primary label-primary">
	<input type="radio" name="options" id="option1" autocomplete="off"> A
  </label>
  <label v-on:click="clearEntries" class="btn btn-primary label-primary">
	<input type="radio" name="options" id="option2" autocomplete="off"> B
  </label>
  <label v-on:click="clearEntries" class="btn btn-primary active label-primary">
	<input type="radio" name="options" id="option3" autocomplete="off" checked> C
  </label>
   <label v-on:click="clearEntries" class="btn btn-primary label-primary">
	<input type="radio" name="options" id="option4" autocomplete="off"> D
  </label>
</div>
</div>

关于javascript - 无法从 VueJS 监听 Bootstrap 按钮组内的点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43089314/

相关文章:

javascript - 哪些浏览器允许 javascript 作为图像标签的来源?

html - 如何使按钮大小相同并在页面上居中?

reactjs - 混合使用 React 和 Vue 是个好主意吗?

javascript - 视觉 : Getting the router instance in children components

javascript - 通过单击返回错误的按钮在 Vue 中添加新的组件实例

javascript - RegEx 实时反转

javascript - 将 bean 值提取为字符串以供 Javascript 使用

javascript - 如何使用 .jsx 或 .idjs 在 InDesign 中编写批量图像放置代码?

jquery - Bootstrap 日期选择器隐藏在模态中

html - 输入组卡在导航栏后面