【发布时间】:2020-08-04 15:26:39
【问题描述】:
我做了一支笔,所以你可以看到我在说什么:https://codepen.io/cristian-ayala/pen/rNOWwOO?editors=1111
输入和段落都绑定到 Vue (anioPicker) 的值,但 1 秒后我用 jquery 更改了值,但 vue 没有检测到更改,或者我没有正确注册事件。即使我已经更改了段落,它仍然显示 2020,但在 vue 实例中仍然是 2020。如果我输入或删除某些内容,Vue 只会反映更改。你能告诉我我做错了什么吗?
感谢您的帮助。
var vm = new Vue({
el: '#appRESBAR',
data: {
anioPicker: 2020,
},
methods:{
},
watch: {
anioPicker: function(value) {
console.log("watched property",value);
}
}
});
$(window).on("load", function(e) {
setTimeout(function() {
$("#anioDate").val(2012);
console.log(document.querySelector('.yearpicker').value)
}, 1000);
});
.datePick {
display: inline-block;
background: #828282;
transform: skew(-10deg);
padding-left: 10px;
font-weight: 500;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
padding-right: 10px;
margin-top: 0.5rem;
text-align: center;
margin-bottom: 0.5rem;
color: #ffffff;
}
.selectedDate {
background-color: #224abed6;
}
.styleInput{
margin: 0px;
width: 38px;
color: white;
background: #4466c8;
border: none;
padding: 0;
outline: none;
border-radius: 0;
}
<div id="appRESBAR" style="text-align: center;">
<div class="datePick selectedDate">
<input type="text" id="anioDate" class="yearpicker styleInput" style="margin: 0;" v-model="anioPicker"></input>
</div>
<p>La fecha es: {{ anioPicker }}</p>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
【问题讨论】:
标签: javascript jquery vue.js vue-reactivity