错误实例 (没采用单向数据流)
父组件 : <template> <div> 父组件 : {{data.name}} - {{data.age}} - {{data.hight}} <hr> <Hello :data="data"></Hello> </div> </template> <script> import Hello from './components/Hello.vue' import {reactive} from 'vue' export default { components:{ Hello }, setup(){ const data = reactive({ name:'吴宇腾', age:39, hight:1.88 }) return { data } } } </script>
<template> <div> 子组件 : {{data.name}} - {{data.age}} - {{data.hight}} <br> <button @click="data.name = '杨浩楠' ,data.age++">错误师范,不知道单向数据流,直接修改传递过来的值</button> </div> </template> <script> export default { name:'Hello', props:['data'], setup(props,context){ } } </script> <style> </style>
本文来自博客园,作者:杨建鑫,转载请注明原文链接:https://www.cnblogs.com/qd-lbxx/p/16619331.html