vue3 声明变量参数 ref 和 reactive()

553 阅读1分钟

vue3中使用的变量声明和vue2中不同

//改变对应ref的值

//xx 对应 ref的名字
xx.value = xxx

对象

//有值

const info = ref({
  date         : '',
  now          : 0,
  height       : 0,
  low          : 0,
  type         : 'xxx',
  windDirection: 'xxx',
  windPower    : 'xx'
})

//无值

const info = ref({})

动态对象

当你的对象是表单等需要动态绑定或者更新值的对象

const formModal = reactive({
  id           : '',
  roleName     : '',
  authorityName: '',
  isEnable     : 1
})

这样才能v-model绑定或者watch监听

Number

const volume = ref(100)

null

const preview3 = ref(null)

布尔

const isInit = ref(false)

数组

const showIconList = ref([])

String

const keyword = ref('')