我目前使用Vue.JS 2.0,我想从一个自定义指令更新一个Vue实例的模型,但是我看起来很好的方法,这是因为我试图创建一个实现JQueryUI-Datepicker代码的自定义指令如下:
<input type="text" v-datepicker="app.date" readonly="readonly"/>
Vue.directive('datepicker', {
bind: function (el, binding) {
$(el).datepicker({
onSelect: function (date) {
//this is executed every time i choose an date from datepicker
//pop.app.date = date; //this work find but is not dynamic to parent and is very dirty
Vue.set(pop, binding.expression, date); //this should work but nop
}
});
},
update: function (el, binding) {
$(el).datepicker('setDate', binding.value);
}
});
var pop = new Vue({
el: '#popApp',
data: {
app: {
date: ''
}
} …Run Code Online (Sandbox Code Playgroud) 我在 bootstrap 4.4 中使用 vuejs。重构我想从调用方法转移到使用的代码v-model(为了清楚起见,省略了一些引导标记)。单选按钮组模仿https://getbootstrap.com/docs/4.0/components/buttons/#checkbox-and-radio-buttons:
{{mode}}
<div class="btn-group btn-group-toggle py-4 mb-2" data-toggle="buttons">
<label>
<input type="radio" name="mode" value="off" v-model="mode">Stop</input>
</label>
<label>
<input type="radio" name="mode" value="now" v-model="mode">Sofort</input>
</label>
</div>
Run Code Online (Sandbox Code Playgroud)
mode 是一个简单的属性:
data: function () {
return {
mode:"pv",
};
},
Run Code Online (Sandbox Code Playgroud)
不幸的是,在使用v-on:click="setMode(...)"to从以前的实现更改后v-model,mode永远不会更新,也没有给出错误。
bootstrap 文档说明:
这些按钮的选中状态仅通过按钮上的单击事件更新
这可能与 vuejs 的v-model处理冲突吗?如何v-model与引导无线电组一起工作?