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

海口网站建设价格wordpress怎么在虚拟主机上搭建

海口网站建设价格,wordpress怎么在虚拟主机上搭建,美食网站页面设计模板,wordpress 问卷插件一、通信方式 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.yayakq.cn/news/571667/

相关文章:

  • idea网站开发网站建设招聘简介
  • 做网站看好金石网络南阳网站建设哪家专业
  • html5 国外网站做推广的网站有哪些
  • 做统计的网站做企业网站需要什么
  • 福州餐饮网站建设网站中数据查询如何做
  • 室内设计软件下载网站大全360优化大师旧版
  • 宁海县建设局网站计算机网络培训课程
  • 长沙网站优化推广方案工业软件开发技术就业前景
  • 楚雄州城乡建设局网站线上编程课
  • 三门峡市住房的城乡建设局网站建站软件
  • wordpress文章图片本地化在线网站seo诊断
  • 医疗类网站前置审批烟台网站seo外包
  • 网站建设 成本分析英文网站数据库如何建设
  • 响应式网站文章地图网站抓取
  • 网站手机端优化外贸网站建设定制开发
  • 如何维护自己的网站苏州注册公司多少钱
  • 东莞石龙网站建设定制flash网站建设技术是什么
  • 顶尖网站建设建设银行信用卡进度查询官方网站
  • 企业网站 开源百度seo综合查询
  • 惠州网站建设公司哪家好查看网站是否做百度推广
  • 公司网站建设需要些什么要求科技创新的重要性和意义
  • 最新仿58同城网站源码北京网页设计公司有哪些
  • 找外包公司做网站的好处和坏处wordpress 搭建教程
  • 优化网站搭建wordpress 注册 中文
  • 陇南地网站建设柯桥做网站
  • 恶意网站是怎么实现的seo关键词推广公司
  • 用什么网站能直接做dj怎么做营销型网站
  • 建设一个最普通网站要多少钱wordpress获取栏目名称
  • 网站建设和风险评估如何提升网站访问速度
  • 网站集约化建设讲话系统开发