亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue中 this.$set的用法詳解

 更新時(shí)間:2019年09月06日 08:22:23   作者:yang  
這篇文章主要介紹了vue中 this.$set的用法詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

當(dāng)vue的data里邊聲明或者已經(jīng)賦值過的對象或者數(shù)組(數(shù)組里邊的值是對象)時(shí),向?qū)ο笾刑砑有碌膶傩裕绻麓藢傩缘闹?,是不?huì)更新視圖的。

<template>
 <div id="app">
  <p v-for="item in items" :key="item.id">{{item.message}}</p>
  <button class="btn" @click="handClick()">更改數(shù)據(jù)</button>
 </div>
</template>

<script>
export default {
 name: 'App',
 data () {
  return {
   items: [
        { message: "one", id: "1" },
        { message: "two", id: "2" },
        { message: "three", id: "3" }
      ]
  }
 },
 mounted () {
   this.items[0] = { message:'first',id:'4'} //此時(shí)對象的值更改了,但是視圖沒有更新
  // let art = {message:'first',id:"4"}
  // this.$set(this.items,0,art) //$set 可以觸發(fā)更新視圖
 },
 methods: {
  handClick(){
   let change = this.items[0]
   change.message="shen"
   this.$set(this.items,0,change)
  }
 }
}
</script>

<style>

</style>

調(diào)用方法: Vue.set( target , key , value)

  • target: 要更改的數(shù)據(jù)源(可以是一個(gè)對象或者數(shù)組)
  • key 要更改的具體數(shù)據(jù) (索引)
  • value 重新賦的值

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論