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

企业门户网站建设教程网络营销的目标

企业门户网站建设教程,网络营销的目标,河南高端网站,网页小游戏斗地主一、通信方式 Props 和 Events:通过父组件传递 props 给子组件,子组件使用 $emit 发送事件到父组件。Event Bus:使用一个中央事件总线来跨组件通信。Vuex:使用 Vuex 进行全局状态管理,以便在任何组件间共享状态。Prov…

一、通信方式

  • Props 和 Events:通过父组件传递 props 给子组件,子组件使用 $emit 发送事件到父组件。
  • Event Bus:使用一个中央事件总线来跨组件通信。
  • Vuex:使用 Vuex 进行全局状态管理,以便在任何组件间共享状态。
  • Provide / Inject:祖先组件使用 provide 传递数据,后代组件通过 inject 接收数据。
  • $refs:父组件通过 ref 获取子组件实例,直接调用其方法或访问属性。
  • Scoped Slots:使用插槽在父组件中传递数据到子组件,允许子组件根据传递的数据进行渲染。

二、应用举例 

1、Props 和 Events: 

        父组件 (Parent.vue

<template><Child :message="parentMessage" @update="handleUpdate" />
</template>
<script>
export default {data() {return { parentMessage: 'Hello from parent' };},methods: {handleUpdate(newMessage) {this.parentMessage = newMessage;}}
}
</script>

        子组件 (Child.vue

<template><button @click="updateParent">Update Parent</button>
</template>
<script>
export default {props: ['message'],methods: {updateParent() {this.$emit('update', 'Hello from child');}}
}
</script>

2、Event Bus: 

        事件总线 (eventBus.js

import Vue from 'vue';
export const EventBus = new Vue();

        发送消息 (ComponentA.vue

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

        接收消息 (ComponentB.vue

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

3、Vuex: 

         Vuex Store (store.js)

import Vue from 'vue';
import Vuex from 'vuex';Vue.use(Vuex);export default new Vuex.Store({state: {message: 'Hello from Vuex'},mutations: {setMessage(state, newMessage) {state.message = newMessage;}}
});

        更新消息 (ComponentA.vue

<template><button @click="updateMessage">Update Message</button>
</template>
<script>
import { mapMutations } from 'vuex';
export default {methods: {...mapMutations(['setMessage']),updateMessage() {this.setMessage('Hello from Component A');}}
}
</script>

        显示消息 (ComponentB.vue

<template><p>{{ message }}</p>
</template>
<script>
import { mapState } from 'vuex';
export default {computed: {...mapState(['message'])}
}
</script>

4、Provide / Inject: 

        提供数据 (Ancestor.vue

<template><Descendant />
</template>
<script>
export default {provide() {return {message: 'Hello from ancestor'};}
}
</script>

        注入数据 (Descendant.vue

<template><p>{{ message }}</p>
</template>
<script>
export default {inject: ['message']
}
</script>

5、$refs: 

        父组件 (Parent.vue)         

<template><Child ref="childComponent" /><button @click="callChildMethod">Call Child Method</button>
</template>
<script>
import Child from './Child.vue';
export default {components: { Child },methods: {callChildMethod() {this.$refs.childComponent.someMethod();}}
}
</script>

         子组件 (Child.vue)

<template><p>Child Component</p>
</template>
<script>
export default {methods: {someMethod() {console.log('Method in child called!');}}
}
</script>

6、Scoped Slots: 

        父组件 (Parent.vue

<template><Child><template v-slot:default="slotProps"><p>{{ slotProps.message }}</p></template></Child>
</template>
<script>
import Child from './Child.vue';
export default {components: { Child }
}
</script>

         子组件 (Child.vue)

<template><slot :message="'Hello from child'"></slot>
</template>
<script>
export default {}
</script>
http://www.dtcms.com/wzjs/196306.html

相关文章:

  • 做网站和网页区别什么是软文
  • 课程网站开发背景和意义百度电商推广
  • 电商网站开发难点搜索引擎seo是什么意思
  • 大兴专业网站建设价钱网络服务中心
  • 品牌网站的愿望清单怎么做长沙官网seo推广
  • 网站内部优化是什么网络推广员的前景
  • 响应式网站的开发深圳市前十的互联网推广公司
  • 上海网站开发毕业生网络营销题库及答案2020
  • 公司网站建设需要些什么要求西安网站建设公司
  • 做线下极限运动的网站智能搜索引擎
  • 网站快速优化南京seo推广
  • 做视频网站需要什么资质qq排名优化网站
  • 动态网站php代做百度用户服务中心
  • 哪家建设网站武汉seo优化排名公司
  • 厦门网站做的比较好如何在百度发视频推广
  • 汕头免费自助建站模板seo关键词优化报价
  • 香港公司怎么在大陆做网站广告营销公司
  • 做网站需要学习多久整站优化排名
  • 无刷新网站免费网络推广的方法
  • 做网站学费多少钱郑州seo技术服务顾问
  • 现在的网站设计百度指数的搜索指数代表什么
  • 个人网站设计作品图片甘肃百度推广电话
  • dw做一个小网站教程微信营销平台哪个好
  • 邯郸网站建设效果宜兴网站建设
  • 西安SEO网站建设企业网络营销目标
  • 网站建设管理教程郑州竞价托管代运营
  • 全面的网站建设百度快照不更新怎么办
  • 广西住房和城乡建设厅培训中心网扬州百度seo公司
  • 建立的意思长沙企业seo服务
  • 跨境电子商务网页制作与网站建设北京seo设计公司