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

旅游景点网站策划书微信怎么引流营销呢

旅游景点网站策划书,微信怎么引流营销呢,做企业展示型网站,网站建设公司招人vue3中v-on"$listeners"发生了什么 在 Vue 3 的虚拟 DOM 中&#xff0c;事件监听器现在只是以 on 为前缀的 attribute&#xff0c;这样它就成为了 $attrs 对象的一部分&#xff0c;因此 $listeners 被移除了。 <template><label><input type"t…

vue3中v-on="$listeners"发生了什么

在 Vue 3 的虚拟 DOM 中,事件监听器现在只是以 on 为前缀的 attribute,这样它就成为了 $attrs 对象的一部分,因此 $listeners 被移除了

<template><label><input type="text" v-bind="$attrs" /></label>
</template>
<script>
export default {inheritAttrs: false
}
</script>

如果这个组件接收一个 id attribute 和一个 v-on:close 监听器,那么 $attrs 对象现在将如下所示:

{id: 'my-input',onClose: () => console.log('close 事件被触发')
}

需要删除所有的 $listeners 用法(vue2切换vue3的时候)

如何进行改造

1. 直接使用 v-on 绑定具体的事件

在 Vue 3 中,可以直接在子组件上使用 v-on 绑定具体的事件,而不是使用 $listeners。这种方式更明确,也更符合 Vue 3 的设计哲学。

<!-- 父组件 -->
<template><ChildComponentv-on:child-event="handleChildEvent"v-on:another-event="handleAnotherEvent"/>
</template><script>
import ChildComponent from './ChildComponent.vue';export default {components: {ChildComponent},methods: {handleChildEvent() {console.log('Child event triggered');},handleAnotherEvent() {console.log('Another event triggered');}}
};
</script>
<!-- 子组件 -->
<template><div><button @click="$emit('child-event')">Trigger Child Event</button><button @click="$emit('another-event')">Trigger Another Event</button></div>
</template>

2. 使用 emits 选项声明事件

Vue 3 引入了 emits 选项,用于显式声明组件可以触发的事件。这有助于类型检查和文档生成。

<!-- 父组件 -->
<template><ChildComponentv-on:child-event="handleChildEvent"v-on:another-event="handleAnotherEvent"/>
</template><script>
import ChildComponent from './ChildComponent.vue';
export default {components: {ChildComponent},emits: ['child-event', 'another-event'],methods: {handleChildEvent() {console.log('Child event triggered');},handleAnotherEvent() {console.log('Another event triggered');}}
};
</script>
<!-- 子组件 -->
<script>
export default {emits: ['child-event', 'another-event']
};
</script><template><div><button @click="$emit('child-event')">Trigger Child Event</button><button @click="$emit('another-event')">Trigger Another Event</button></div>
</template>

3、使用组合式 API (Composition API)

如果你使用的是 Vue 3 的组合式 API,可以通过 emits 和 defineEmits 来处理事件。

<!-- 父组件 -->
<template><ChildComponentv-on:child-event="handleChildEvent"v-on:another-event="handleAnotherEvent"/>
</template><script setup>
import ChildComponent from './ChildComponent.vue';const handleChildEvent = () => {console.log('Child event triggered');
};const handleAnotherEvent = () => {console.log('Another event triggered');
};
</script>
<!-- 子组件 -->
<script setup>
const emit = defineEmits(['child-event', 'another-event']);
</script><template><div><button @click="emit('child-event')">Trigger Child Event</button><button @click="emit('another-event')">Trigger Another Event</button></div>
</template>

4、直接使用 $attrs 绑定事件监听器

在 Vue 3 中,$listeners 已经被并入 $attrs,所以你可以直接使用 $attrs 来绑定事件监听器。

<!-- 父组件 -->
<template><ChildComponent@child-event="handleChildEvent"@another-event="handleAnotherEvent"/>
</template><script>
import ChildComponent from './ChildComponent.vue';export default {components: {ChildComponent},methods: {handleChildEvent() {console.log('Child event triggered');},handleAnotherEvent() {console.log('Another event triggered');}}
};
</script>
<!-- 子组件 -->
<template><div v-bind="$attrs"><button @click="$emit('child-event')">Trigger Child Event</button><button @click="$emit('another-event')">Trigger Another Event</button></div>
</template><script>
export default {inheritAttrs: false // 可选,如果不希望根元素自动接收 $attrs
};
</script>
http://www.dtcms.com/wzjs/170482.html

相关文章:

  • 中国建设银行网站软件优化绿松石什么意思
  • 东莞外贸企业网站建设关联词有哪些小学
  • 资讯网站开发需求石家庄最新疫情最新消息
  • PHP MySQL 网站开发实例线上购买链接
  • 幼儿园微信网站怎么做长沙百度快照优化排名
  • 网站怎么做虚拟连接昨日凌晨北京突然宣布重大消息
  • 男人直接做的视频网站朋友圈软文范例
  • 企业营销型网站建设费用军事网站大全军事网
  • 网站排名提升软件关键词优化的发展趋势
  • 装修网站开发前的准备工作站长素材官网免费
  • 销售渠道都有哪些seo培训学院官网
  • 来宾网站优化桔子seo工具
  • 一级a做爰片免费的网站有吗昆山网站制作哪家好
  • 新疆生产建设兵团棉麻公司网站安徽百度seo公司
  • 天津网站建设排名肇庆seo排名
  • 网站用哪些系统做的比较好网站关键词快速优化
  • 建立百度网站外贸网站推广方式
  • 什么是营销型网站现在推广用什么平台
  • 网站是用什么技术做的北京网络营销策划公司
  • 自己做游戏app的网站宁波网络推广公司有哪些
  • 四川华海建设集团有限公司网站谷歌推广一年多少钱
  • 广州做网站多少钱广州谷歌seo
  • 网站后台帐号厦门人才网唯一官网
  • 综合门户型网站有哪些seo01网站
  • flash怎么做网站北京网站建设东轩seo
  • 北京html5网站建设微信营销工具
  • 怎么给公司做网站教你如何建立网站
  • 网络营销服务市场目前主要的服务是360优化大师安卓版下载
  • 提供企业网站建设方案seo课程排行榜
  • 广州和信建设公司网站济南优化网页