米
心情
所有
图集
登录
搜索
原创
vue子组件向父组件传值(父子组件传值)
终于白首
发布于:2020-12-10
一直都是坐着杂七杂八的混合复杂开发,前端一直都是一知半解的状态。这次趁着项目经验,趁热记录一下。相信后面自己会用到,大家也有可能用到。 父组件代码: ``` //parentFn 在父页面中处理的函数 childFn在子页面【Huati页面】需要处理的函数 <Huati @childFn="parentFn"></Huati> <script> import Huati from "@/components/opt/article/huati" export default { name: 'voi', data() { return { form: { description:'' } }; }, methods: { parentFn(payload) { //负组件获取子组件的值 console.log(payload); this.form.description = payload }, }, created() { }, mounted() { }, components: { UpLoadFile, Huati } } </script> ``` 子页面 ``` <template> <div class="testCom"> <input type="text" v-model="message" /> <button @click="click">Send</button> </div> </template> <script> export default { // ... data() { return { // 默认 message: '我是来自子组件的消息' } }, methods: { click() { this.$emit('childFn', this.message); //通过childFn 将值传递给父页面 } } } </script> ```
注:原创不易,转载请注明出处(
https://micuu.com/new/1090.html
),本站所有资源来源于网络收集,如有侵权请联系QQ245557979进行清除。
最后修改与 2022-02-21
上一篇:
时光如此,我亦如此!
下一篇:
贵州网红 炸爆米花的抖音号是多少 ?
▶
珍藏视频
▶
10分钟高效燃脂
▶
30天高效瘦脸操
▶
5分钟缓解颈椎操
友人
→
微博
→
全民K歌
→
唱吧
→
今日头条
→
悠悠网
→
科技小锅盖
→
彼岸桌面
→
阮一峰
→
laravel社区
→
V2ex
→
掘金
+
更多