当前位置: 首页 > wzjs >正文

免费游戏网站建设哪个网站是教人做淘宝客的

免费游戏网站建设,哪个网站是教人做淘宝客的,超级外链工具,网站页面设计最宽可做多宽在 Vue 中&#xff0c;组件之间的传值方式主要包括以下几种情况&#xff1a; 1. 父组件向子组件传值&#xff08;props&#xff09; 父组件通过 props 传递数据给子组件&#xff1a; <!-- Parent.vue --> <template><ChildComponent :msg"message"…

在 Vue 中,组件之间的传值方式主要包括以下几种情况:

1. 父组件向子组件传值(props

父组件通过 props 传递数据给子组件:

<!-- Parent.vue -->
<template><ChildComponent :msg="message" />
</template><script>
import ChildComponent from './ChildComponent.vue';
export default {components: { ChildComponent },data() {return {message: 'Hello from Parent!'};}
};
</script>
<!-- ChildComponent.vue -->
<template><p>Received message: {{ msg }}</p>
</template><script>
export default {props: {msg: String}
};
</script>

2. 子组件向父组件传值($emit

子组件通过 this.$emit 触发事件,父组件监听事件并获取值:

<!-- Parent.vue -->
<template><ChildComponent @update-message="handleMessage" /><p>Message from Child: {{ receivedMessage }}</p>
</template><script>
import ChildComponent from './ChildComponent.vue';
export default {components: { ChildComponent },data() {return {receivedMessage: ''};},methods: {handleMessage(msg) {this.receivedMessage = msg;}}
};
</script>
<!-- ChildComponent.vue -->
<template><button @click="sendMessage">Send to Parent</button>
</template><script>
export default {methods: {sendMessage() {this.$emit('update-message', 'Hello from Child!');}}
};
</script>

3. 兄弟组件传值(Event BusPinia/Vuex

兄弟组件需要一个中间桥梁,比如 Event Bus(Vue 3 不推荐)或 Pinia(推荐):

// eventBus.js (Vue 2 可用,Vue 3 推荐使用 Pinia)
import Vue from 'vue';
export const EventBus = new Vue();

BrotherA.vue 发送数据:

<template><button @click="sendMessage">Send to BrotherB</button>
</template><script>
import { EventBus } from './eventBus.js';
export default {methods: {sendMessage() {EventBus.$emit('message', 'Hello from BrotherA!');}}
};
</script>

BrotherB.vue 接收数据:

<template><p>{{ receivedMessage }}</p>
</template><script>
import { EventBus } from './eventBus.js';
export default {data() {return { receivedMessage: '' };},created() {EventBus.$on('message', msg => {this.receivedMessage = msg;});}
};
</script>

4. ref 方式(获取子组件实例)

父组件可以通过 ref 获取子组件实例并访问其方法或数据:

<!-- Parent.vue -->
<template><ChildComponent ref="childRef" /><button @click="callChildMethod">Call Child Method</button>
</template><script>
import ChildComponent from './ChildComponent.vue';
export default {components: { ChildComponent },methods: {callChildMethod() {this.$refs.childRef.childMethod();}}
};
</script>
<!-- ChildComponent.vue -->
<template><p>Child Component</p>
</template><script>
export default {methods: {childMethod() {console.log('Child method called!');}}
};
</script>

5. provideinject(适用于祖孙组件)

适用于跨层级组件通信:

<!-- GrandParent.vue -->
<template><Parent />
</template><script>
import Parent from './Parent.vue';
export default {components: { Parent },provide() {return { sharedMessage: 'Hello from GrandParent!' };}
};
</script>
<!-- Parent.vue -->
<template><Child />
</template><script>
import Child from './Child.vue';
export default {components: { Child }
};
</script>
<!-- Child.vue -->
<template><p>{{ sharedMessage }}</p>
</template><script>
export default {inject: ['sharedMessage']
};
</script>

6. Vuex 或 Pinia(全局状态管理)

适用于复杂状态管理,如 Vuex(Vue 2)或 Pinia(Vue 3):

// store.js (使用 Pinia)
import { defineStore } from 'pinia';export const useMainStore = defineStore('main', {state: () => ({message: 'Hello from Store'}),actions: {setMessage(newMsg) {this.message = newMsg;}}
});

ComponentA.vue 更新数据:

<template><button @click="updateMessage">Update Message</button>
</template><script>
import { useMainStore } from './store.js';
export default {setup() {const store = useMainStore();const updateMessage = () => store.setMessage('Updated Message!');return { updateMessage };}
};
</script>

ComponentB.vue 读取数据:

<template><p>{{ store.message }}</p>
</template><script>
import { useMainStore } from './store.js';
export default {setup() {const store = useMainStore();return { store };}
};
</script>


文章转载自:

http://Frq8F9j6.nzkkh.cn
http://79FblVcW.nzkkh.cn
http://W5XgkGCK.nzkkh.cn
http://8H1UMsEt.nzkkh.cn
http://Q4Wwytc1.nzkkh.cn
http://JzZPrKkn.nzkkh.cn
http://W25oJrfP.nzkkh.cn
http://gtSAvTpG.nzkkh.cn
http://jSUNVJNc.nzkkh.cn
http://ATtQSUNC.nzkkh.cn
http://JBrHDZnX.nzkkh.cn
http://fcJIbkDP.nzkkh.cn
http://WGhvkFYl.nzkkh.cn
http://eT5TLoBj.nzkkh.cn
http://IoOmaiaZ.nzkkh.cn
http://7vBf1Xys.nzkkh.cn
http://yCUAYry6.nzkkh.cn
http://2jznFC1v.nzkkh.cn
http://V4RwPjEP.nzkkh.cn
http://OaPdxidv.nzkkh.cn
http://JyRQp7HS.nzkkh.cn
http://8ZNUC2nx.nzkkh.cn
http://4BMT3RcR.nzkkh.cn
http://6f3tH0iQ.nzkkh.cn
http://dEFZUTur.nzkkh.cn
http://L7u3SVdD.nzkkh.cn
http://DruyX5Un.nzkkh.cn
http://j08YqA9H.nzkkh.cn
http://BICLpGlQ.nzkkh.cn
http://hZzmUhMD.nzkkh.cn
http://www.dtcms.com/wzjs/759392.html

相关文章:

  • 网站建设公司哪里有最近的新闻有哪些
  • 网站建设业务拓展思路godaddy wordpress 备
  • 南海建设工程交易中心网站微信小程序开发制作多少钱
  • 公司网站设计要求做名片模板网站
  • 手机网站维护费成都网站建设服务公司
  • 完成门户网站建设重庆网架加工厂
  • 网站建设支付方式珠海做网站报价
  • 网站开发实验结论网站可信度建设
  • wordpress安装路径和站点地址的设置东莞市做阀门的网站
  • 推广软件的网站wordpress从
  • 网站的二级网页关键词昆明网站设计公司
  • 陕西省住房城乡建设厅网站管理中心企业品牌策划案例
  • 网站制作好吗网站服务器重做系统怎么做
  • 小企业怎么建网站平台给网站挂黑链
  • 法律咨询东莞网站建设电商网站页面
  • 长沙 建站优化深圳网站建设公司jm3q
  • 深圳购物网站建设报价怎么做交易网站
  • 好公司网站建设婚庆公司简介
  • 珠海网站建设联系方式秦皇岛建设局局官方网站
  • 公司企业网站设计尺寸仿一个展示型网站多少钱
  • 网站建设常州麦策电商长春百度推广公司
  • 大鼠引物在线设计网站河源seo排名
  • 专业3合1网站建设个人购买链接
  • 做网站用什么软件最好靖江网站制作多少钱
  • 石家庄网站优化招聘网站换空间会影响排名吗
  • 浩森宇特北京网站设计wordpress固定链接设置后进入不
  • 长沙的互联网网站公司如何编程做网站
  • 网站建设开发背景中企动力有限公司官网
  • 如何在电脑上建立网站手机兼职任务平台
  • 儋州网站建设大学生个人网站制作