我是Vuejs的新手.做了些什么,但我不知道这是简单/正确的方式.
我想要的是
我想在数组中有一些日期并在事件上更新它们.首先我尝试了Vue.set,但它没有成功.现在更改我的数组项后:
this.items[index] = val;
this.items.push();
Run Code Online (Sandbox Code Playgroud)
我推送()没有任何数组,它会更新..但有时最后一项将被隐藏,不知何故......我认为这个解决方案有点hacky,我怎么能让它稳定?
简单的代码在这里:
new Vue({
el: '#app',
data: {
f: 'DD-MM-YYYY',
items: [
"10-03-2017",
"12-03-2017"
]
},
methods: {
cha: function(index, item, what, count) {
console.log(item + " index > " + index);
val = moment(this.items[index], this.f).add(count, what).format(this.f);
this.items[index] = val;
this.items.push();
console.log("arr length: " + this.items.length);
}
}
})Run Code Online (Sandbox Code Playgroud)
ul {
list-style-type: none;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.11/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
<div id="app">
<ul>
<li v-for="(index, item) in items">
<br><br>
<button v-on:click="cha(index, item, 'day', -1)">
- …Run Code Online (Sandbox Code Playgroud)