vue3.0 ref 和reactive 制空数组的方式 (两者是有差异的)

  1.采用 reactive 制空数组
     let goodList = reactive([
      {
    
    
        id: 1,
        title: '苹果'
      },
      {
    
    
        id: 2,
        title: '鸭梨'
      }
  ])
  正常想法   goodList  = []  //但是这样是不行的 
  正确  	goodList.length = 0; 
  //--------------------------分割------------------------//
  2.ref 的方式
    let goodList = ref([
      {
    
    
        id: 1,
        title: '苹果'
      },
      {
    
    
        id: 2,
        title: '鸭梨'
      }
  ])
  这种情况就随意了    
  goodList.value.length = 0;   
  goodList.value = [];

猜你喜欢

转载自blog.csdn.net/weixin_45932463/article/details/121274394
今日推荐