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

如何在网站上做推广弄一个公司官网要怎么弄

如何在网站上做推广,弄一个公司官网要怎么弄,wordpress 大型分离,网络课程网站建设在 Vue3 中&#xff0c;组件之间的数据传递主要有以下几种方式&#xff0c;适用于不同的场景&#xff1a; 一、父组件向子组件传值&#xff1a;props 1. 子组件定义 props <!-- ChildComponent.vue --> <script setup> // 组合式 API&#xff08;推荐&#xff09…

在 Vue3 中,组件之间的数据传递主要有以下几种方式,适用于不同的场景:


一、父组件向子组件传值:props

1. 子组件定义 props
<!-- ChildComponent.vue -->
<script setup>
// 组合式 API(推荐)
const props = defineProps({title: {type: String,default: '默认标题'},count: {type: Number,required: true}
});
</script><template><div>{{ title }} - {{ count }}</div>
</template>
<!-- 选项式 API -->
<script>
export default {props: {title: String,count: {type: Number,required: true}}
}
</script>
2. 父组件传递数据
<template><ChildComponent :title="'Hello Vue3'" :count="42"/>
</template>

二、子组件向父组件传值:emit 事件

1. 子组件触发事件
<!-- ChildComponent.vue -->
<script setup>
const emit = defineEmits(['updateCount']); // 定义事件function increment() {emit('updateCount', 10); // 触发事件并传递数据
}
</script><template><button @click="increment">增加计数</button>
</template>
2. 父组件监听事件
<template><ChildComponent :count="count"@updateCount="count = $event" <!-- 接收子组件传递的值 -->/>
</template><script setup>
import { ref } from 'vue';
const count = ref(0);
</script>

三、双向绑定:v-model

1. 子组件支持 v-model
<!-- ChildComponent.vue -->
<script setup>
const props = defineProps(['modelValue']);
const emit = defineEmits(['update:modelValue']);function updateValue(newValue) {emit('update:modelValue', newValue);
}
</script><template><input :value="modelValue" @input="updateValue($event.target.value)">
</template>
2. 父组件使用 v-model
<template><ChildComponent v-model="text" /> <!-- 自动同步数据 -->
</template><script setup>
import { ref } from 'vue';
const text = ref('初始值');
</script>

四、跨层级传值:provide / inject

1. 祖先组件提供数据
<!-- AncestorComponent.vue -->
<script setup>
import { provide, ref } from 'vue';const theme = ref('dark');
provide('theme', theme); // 提供数据
</script>
2. 后代组件注入数据
<!-- ChildComponent.vue -->
<script setup>
import { inject } from 'vue';const theme = inject('theme'); // 注入数据
</script><template><div :class="theme">当前主题:{{ theme }}</div>
</template>

五、通过 Context 共享数据(如 Pinia 状态管理)

1. 安装 Pinia
npm install pinia
2. 创建 Store
// stores/counter.js
import { defineStore } from 'pinia';export const useCounterStore = defineStore('counter', {state: () => ({count: 0}),actions: {increment() {this.count++;}}
});
3. 组件中使用 Store
<template><div>Count: {{ counterStore.count }}</div><button @click="counterStore.increment()">+1</button>
</template><script setup>
import { useCounterStore } from '@/stores/counter';const counterStore = useCounterStore();
</script>

总结:不同场景的传值方式

场景方法适用性
父子组件直接通信props + emit父子层级明确,数据流单向
表单输入双向绑定v-model表单类组件(如输入框、下拉框)
跨层级组件通信provide / inject深层次嵌套组件(如全局配置、主题)
复杂应用状态共享Pinia / Vuex多组件共享状态(推荐中大型项目)

推荐实践

  • 优先使用 propsemit 实现父子通信。
  • 简单双向绑定用 v-model,复杂逻辑用事件。
  • 跨层级或全局状态使用 Pinia。
  • 避免过度依赖 provide/inject,可能导致组件耦合。

文章转载自:

http://Q7XC1PhS.xpqyf.cn
http://CxAoQykS.xpqyf.cn
http://8GUezUIW.xpqyf.cn
http://yGjTmO2b.xpqyf.cn
http://hDOD4iws.xpqyf.cn
http://5U7gp9Gt.xpqyf.cn
http://USY0t9rP.xpqyf.cn
http://qM77yJDh.xpqyf.cn
http://j75eQir6.xpqyf.cn
http://OZEfRHoL.xpqyf.cn
http://0NY0qKbI.xpqyf.cn
http://iOxB7fJc.xpqyf.cn
http://367HuF4E.xpqyf.cn
http://pDq53xUU.xpqyf.cn
http://OXM9RDEd.xpqyf.cn
http://fOulw1DG.xpqyf.cn
http://c9AZVPsl.xpqyf.cn
http://PvbqR1PW.xpqyf.cn
http://kGhf2QZP.xpqyf.cn
http://x2kwfbpl.xpqyf.cn
http://SOjnvUR8.xpqyf.cn
http://uE0HpH0I.xpqyf.cn
http://h3PCUshc.xpqyf.cn
http://iqewNdDL.xpqyf.cn
http://yumWbDFB.xpqyf.cn
http://ltpeqkND.xpqyf.cn
http://xOfg39lf.xpqyf.cn
http://iRMyXUfN.xpqyf.cn
http://d9RcAWBl.xpqyf.cn
http://kwUOgFJd.xpqyf.cn
http://www.dtcms.com/wzjs/770674.html

相关文章:

  • 平面设计创意网站建设做网站开票是多少个点的票
  • 彩票网站开发系统如何搭建制作网页整体规划方案
  • 如何做网站优化 纯外链最新新闻热点事件2021年7月
  • 网站建设发展方向昆山网页设计报价
  • 建设局招标网站网络工程师可能自学吗
  • 自己网站首页如何设置槐荫区网络营销seo
  • 叫什么公子的网站做ppt的手机版网站开发价格
  • 17网站一起做网店普宁轻纺城可视化建站源码
  • 哈尔滨网站开发培训普通网站和营销网站有何不同
  • 世纪城网站建设商丘睢阳区市政建设局网站
  • 漳州市城乡建设局网站使用wampserver做响应式网站
  • 外国个人主页网站欣赏付费主题wordpress
  • jsp网站开发标准百度app安装下载免费
  • 做购物网站需要学数据库吗wordpress 修改点击数
  • 陕西建设厅网站人才库wordpress写的软文
  • 养老网站建设wordpress 10万pv
  • 网站备案符号小程序登录入口网址
  • 深圳网络公司网站装修 设计 网站
  • 一般多少钱做一个网站物业管理系统英文
  • 网站建设小程序南宁文本文档做网站
  • 手机营销网站模板动易网站 教程
  • 设计公司网站多少钱如何做网站app
  • 青海省城乡建设信息官官方网站wordpress首页自定义缩略图
  • 公司的网站 优帮云信息产业部 备案网站
  • discuz 网站备案信息代码公司基础建设的意义
  • 初二做网站的首页模板网站建设颜色代码表
  • 网站制定企业网站建设网站有哪些
  • 建设网站有什么原则微信版本的wordpress
  • 网站开发连接数据库的方法洛阳网站建设公司
  • 北京工厂网站建设专业返利网站建设