您当前的位置: 首页 > 

梁云亮

暂无认证

  • 3浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Vue3中computed的使用

梁云亮 发布时间:2021-05-23 12:08:59 ,浏览量:3

方式一
import {computed,reactive} from 'vue'
export default {
  name: "LayoutAside",
  setup() {
    let menuData = reactive(computed(()=>{ //vue3中computed的使用
      return store.state.menus.menuList
    }))

    return {
      menuData
    }
  }
}

方式二

    输入待求平方的数字:
    {{digit}}的平方是:{{square}}



    import { ref, computed } from 'vue'

    export default {
        setup() {
            const digit = ref(1)
            const square = computed(() => {
                return +digit.value * +digit.value
            })
            return {
                digit
            }
        }
    }


方式三

  
    
  



import { computed } from 'vue'
export default {
  setup() {
    const age = computed({
      get() {
        return +age.value+1
      },
      set(value) {
        return age.value = value - 1
      }
    })
    return { 
      age
    }
  }
}
关注
打赏
1665409997
查看更多评论
立即登录/注册

微信扫码登录

0.0416s