vue3.0最新初体験

1147 ワード

vue3.0の初体験
ダイレクトコード


import { ref, computed, watch, getCurrentInstance } from 'vue'

export default {
  setup() {
    const count = ref(0);
    const add = () => {
      count.value++
    }
    watch(() => count.value, val => {
      console.log(`count is ${val}`)
    })
    const doubleCount = computed(() => count.value * 2)
    const { ctx } = getCurrentInstance()
    console.log(ctx.$router.currentRoute.value)
    const a = computed(() => ctx.$store.state.test.a)
    const update = () => {
      ctx.$store.state.test.a = count.value * 3
      //ctx.$store.state.test.a = computed(() => count.value * 4)
      ctx.$store.commit('setTestA', doubleCount)
    }
    return {
      doubleCount,
      count,
      add,
      a,
      update
    }
  }
}


vue2.0はまだ模索中、vue 3.0が来る