软件开发网站开发公司,wordpress 主题 导出,平台网站的策划设计,长沙网站建设1681989在工作中踩了props的坑#xff0c;总结一下#xff1a;
1.props是可以在模板语法中简写的。就好比#xff0c;toRefs了一下state。我们没必要在模板语法中加上props.xxx#xff1b;
2.有时我们需要监视props的内容#xff0c;可以用到监视属性watch。我们可以先复习一下…在工作中踩了props的坑总结一下
1.props是可以在模板语法中简写的。就好比toRefs了一下state。我们没必要在模板语法中加上props.xxx
2.有时我们需要监视props的内容可以用到监视属性watch。我们可以先复习一下watch在Vue3的用法
templatediv学校名称: {{ school }}/divbutton clickschool 家里蹲大学修改学校名称/button
/templatescript
import {ref, reactive, watch} from vue
export default {name: App,setup() {let school ref(湖北师范大学)watch(school, (newValue, oldValue) {console.log(school被修改);console.log(school)})return {school}}
}
/script
具体也可以见一下这篇博客Vue3中watch的value问题
唯独监视props的时候格式不太一样
取一段代码 // 监视属性监视props.tableContentwatch(() props.tableContent,(newValue, oldValue) {console.log(newValue)state.tableForm.records newValue.recordsstate.tableForm.columns newValue.columnsconsole.log(tableForm, state.tableForm)})需要以这样的格式书写才可以正常响应。
最后欢迎关注