Vue.js备忘录
数组的值交换位置
数组数据
data () {
return {
tableData: [1,2,3]
}
}
数组的某一位与前一位交换(例:表格上移)
// index 是索引位置 var tempOption = this.tableData[index - 1] this.$set(this.tableData, index - 1, this.tableData[index]) this.$set(this.tableData, index, tempOption)
数组的某一位与后一位交换(例:表格下移)
//index 是索引位置 var tempOption = this.tableData[index + 1] this.$set(this.tableData, index + 1, this.tableData[index]) this.$set(this.tableData, index, tempOption)
使用watch监听一个对象中的属性
要监视的对象
queryData: {
name: '',
creator: '',
selectedStatus: '',
time: [],
}
方法
watch: {
'queryData.name': {
handler: function() {
//do something
},
}
}
也可以使用计算属性
computed: {
getName: function() {
return this.queryData.name
}
},
watch: {
getName: {
handler: function() {
//do something
},
}
}
发布时间:2020/4/17 上午9:19:42 阅读次数:2627
