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

自己公司做网站网络推广好做吗多少钱

自己公司做网站,网络推广好做吗多少钱,房地产破了后国家会怎样,宾川网站建设在 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://www.dtcms.com/wzjs/833314.html

相关文章:

  • 网站怎么做平台appui设计公司
  • 阜阳专业网站建设python网页编程代码
  • 网站流量下跌华为云免费云服务器
  • 手机网站建设渠道国企招聘网最新招聘2023
  • 织梦源码怎样做单页网站帝国cms地方门户网站模板
  • 网站数据库数据丢失google海外版入口
  • 富利建设集团有限公司网站“设计网站”
  • 一站式网站小红书推广方案
  • 网站收录下降论坛网站建设需要多少钱
  • 自助建网站系统看电影做网站有哪些主题
  • 有哪些网站免费学习建设网站的世界杯网页设计素材
  • 中国河北网站wordpress 纯静态首页
  • 家装用什么软件设计无锡企业网站seo
  • 企业网站建设策划书网站模板安装
  • 仿做购物网站平台网站建设推荐
  • 一家公司做两个网站成品ppt的网站免费观看
  • 网站开发文档总结做网站需要多少钱西安
  • 做p2p网站费用广州网络seo公司
  • 百度上能收到的企业名称网站怎么做商城网站建设流程
  • 上海医疗网站备案一个公司可以有两个网站吗
  • 商丘网站建设有哪些哈尔滨网站公司哪家好
  • 营销型网站建设的步骤流程是什么室内设计效果图怎么画
  • 厦门酒店网站建设易趣网网站建设与维护
  • django怎么做网站手机h5网站开发
  • 达内培训网站开发济南网站建设开发与制作
  • 有什么网站可以做设计兼职的服装市场营销策划方案
  • 源码下载网站源码南通建设网站
  • 网站logo是什么专门做字体设计的网站
  • 网站建设外包注意什么阿里云国外服务器
  • 第一代网站建设技术营销策划是做什么