摘要:const name = ref('张三')const age = ref(18)const isLoading = ref(false)const user = ref({name: '李四'})const list = ref()name.value =
官方文档及尤雨溪提到过 ,ref 一把梭,不建议用 reactive。我说的话不可信,尤雨溪的话百分百可信,用,用,用 ref 一把梭。
const name = ref('张三')const age = ref(18)const isLoading = ref(false)const user = ref({name: '李四'})const list = ref()name.value = '王五' age.value = 20 #技术分享const user = reactive({ name: '张三', age: 18})const form = reactive({ username: '', password: '' })const list = reactive()user.name = '李四' form.username = 'admin'--- 关键区别:重新赋值问题
let list = reactive(['苹果', '香蕉'])setTimeout( => { const newData = ['西瓜', '葡萄', '芒果'] list = newData }, 1000)const list = ref(['苹果', '香蕉'])setTimeout( => { const newData = ['西瓜', '葡萄', '芒果'] list.value = newData }, 1000)const state = reactive({ list: ['苹果', '香蕉']})setTimeout( => { const newData = ['西瓜', '葡萄', '芒果'] state.list = newData }, 1000)const count = ref(0)const name = ref('')const isVisible = ref(true)const data = ref(null)const fetchData = async => { const result = await api.getData data.value = result}const currentPageData = ref() const changePage = (page) => { currentPageData.value = getDataByPage(page) }const form = reactive({ username: '', password: '', remember: false})const userInfo = reactive({ name: '张三', age: 25, avatar: '' })记住:ref 永远不会错,reactive 有时候会坑你!
官方文档及尤雨溪提到过 ,ref 一把梭,不建议用 reactive。我说的话不可信,尤雨溪的话百分百可信,用,用,用 ref 一把梭。不服,不服你不用打我,去打他
来源:墨码行者
免责声明:本站系转载,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权和其它问题,请在30日内与本站联系,我们将在第一时间删除内容!