vue3的ref用法


使用ref函数定义一个变量,ref扩号里是变量的初始值

 import { ref } from 'vue'
let conter=ref(0)
let arr=ref(['我是字符串'])
template里的用法
<button @click="conter++">{{conter}}</button>
  <div v-for="item in arr">
  <p>{{item}}</p>
  </div>

js里的用法

function add(){
    conter.value++
    console.log(conter)
    arr.value.push('耗子尾汁')
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM