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  阅读次数:1578

2006 - 2024,推荐分辨率 1024*768 以上,推荐浏览器 Chrome、Edge 等现代浏览器,截止 2021 年 12 月 5 日的访问次数:1872 万 9823 站长邮箱

沪 ICP 备 18037240 号-1

沪公网安备 31011002002865 号