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

网站名和域名的区别举一个病毒营销的例子

网站名和域名的区别,举一个病毒营销的例子,wordpress商城主题,三亚文明城市建设服务中心报名网站今天产品经理要求做保留某组件全部功能,还要在它的基础上增加东西。如果不嫌麻烦的话就笨办法,但是想一下怎么只用少量代码高效的二次封装组件呢 Vue中的$attrs 在 Vue2 中,attr 是指组件接收的 HTML 特性(attribute),通过 prop…

今天产品经理要求做保留某组件全部功能,还要在它的基础上增加东西。如果不嫌麻烦的话就笨办法,但是想一下怎么只用少量代码高效的二次封装组件呢

Vue中的$attrs

在 Vue2 中,attr 是指组件接收的 HTML 特性(attribute),通过 props 的方式传递给子组件。
而在 Vue3 中,attr 的概念被引入了 Composition API 中,并且被用于管理各种配置项。

Vue2 中使用 attr

1、使用 v-bind指令绑定 HTML 属性
在 Vue2 中,如果想将父组件传递的 HTML 属性传递给子组件进行使用,可以在子组件中通过 props 接收参数,并使用 v-bind 指令将其绑定到子组件的 HTML 元素上。例如:

<template><div class="demo-component" :style="styleObject">{{ message }}</div>
</template><script>
export default {name: "DemoComponent",props: {message: String,styleObject: Object,},
};
</script>

在父组件中使用该组件时,可以通过 v-bind 指令将 HTML 特性传递给子组件:

<template><demo-component message="Hello, world!" :style-object="{ color: 'red' }"></demo-component>
</template>

2、使用 $attrs 对象传递所有未被 props 所接收的特性
在 Vue2 中,可以通过 $attrs 对象获取父组件传递给子组件但未被 props 所接收的特性,从而实现组件复用和扩展的目的。例如:

<template><div class="demo-component" :style="styleObject" v-bind="$attrs">{{ message }}</div>
</template><script>
export default {name: "DemoComponent",props: {message: String,styleObject: Object,},
};
</script>

在父组件使用该组件时,可以像平常传递普通的 HTML 特性一样,同时还可以传递一些自定义的特性:

<template><demo-componentmessage="Hello, world!":style-object="{ color: 'red' }"custom-attribute="something"></demo-component>
</template>

在子组件中,可以通过 this.$attrs 属性获取父组件传递给子组件但未被 props 所接收的特性:

console.log(this.$attrs.customAttribute); // 输出:something

Vue3 中使用 attr

在 Vue3 中,可以通过 setup 函数中的第二个参数 context 来访问该组件的配置选项,其中包括了所有未被 props 所接收的特性:

<template><div class="demo-component" :style="styleObject" v-bind="$attrs">{{ message }}</div>
</template><script>
export default {name: "DemoComponent",props: {message: String,styleObject: Object,},setup(props, context) {console.log(context.attrs.customAttribute); // 输出:something},
};
</script>

在 setup 函数中,通过 context.attrs 获取父组件传递给子组件但未被 props 所接收的特性。
除了 $attrs,Vue3 中还引入了 $props 对象,它是一个由 props 组成的响应式对象,在组件内部通过解构赋值可以快速地访问 props 的属性值:

<template><div class="demo-component" :style="styleObject">{{ message }}</div>
</template><script>
export default {name: "DemoComponent",props: {message: String,styleObject: Object,},setup(props) {const { message, styleObject } = props;console.log(message, styleObject); // 输出:Hello, world! { color: 'red' }},
};
</script>

在 setup 函数中,通过解构赋值可以快速地访问 props 的属性值。

利用 $attrs 和 $listeners 可以在二次封装 element-ui 组件时非常方便地传递组件属性和事件。

示例代码

下面以 el-input 组件为例,演示一下vue2中如何高效地二次封装 element-ui 组件,从而达到只用少量代码在原有组件上升级的效果:

<template><el-input v-bind="$attrs" v-on="$listeners" :class="{ 'is-invalid': isError }"><template v-if="isError" #append><i class="el-input__icon el-icon-circle-close"></i></template></el-input>
</template><script>
export default {name: "MyInput",inheritAttrs: false,props: {isError: Boolean, // 是否显示错误提示},
};
</script>
<style scoped lang="scss">
//这是写自己的样式内容
</style>

讲解:
1、使用 v-bind=“$attrs” 将父级组件所有的未被 props 所接收的特性绑定到 el-input 组件上。

2、使用 v-on=“$listeners” 将父级组件传递给当前组件的所有事件监听器绑定到 el-input 组件上。

3、在模板中可以很方便地使用 isError 属性来扩展组件,并且不需要在父组件中再次定义。

需要注意的是,由于 element-ui 组件本身也包含了一些默认的属性和事件,因此需要在组件中设置 inheritAttrs: false,以避免传递 element-ui 组件自带的属性和事件。


文章转载自:
http://wanjiawap.jtrb.cn
http://wanjiatruthfulness.jtrb.cn
http://wanjiadivinable.jtrb.cn
http://wanjiapeacocky.jtrb.cn
http://wanjialymphadenopathy.jtrb.cn
http://wanjiabanditi.jtrb.cn
http://wanjialeptophyllous.jtrb.cn
http://wanjiasilliness.jtrb.cn
http://wanjiatransuranium.jtrb.cn
http://wanjiamercenarism.jtrb.cn
http://wanjiahencoop.jtrb.cn
http://wanjiavigorous.jtrb.cn
http://wanjiacompotation.jtrb.cn
http://wanjiamondial.jtrb.cn
http://wanjiaimperceptibly.jtrb.cn
http://wanjiasaktism.jtrb.cn
http://wanjiasequestrable.jtrb.cn
http://wanjiaelectrosensitive.jtrb.cn
http://wanjiacurvature.jtrb.cn
http://wanjiaapaprthotel.jtrb.cn
http://wanjianoninitially.jtrb.cn
http://wanjiaunvoiced.jtrb.cn
http://wanjiaastronome.jtrb.cn
http://wanjiahemipode.jtrb.cn
http://wanjiauncloister.jtrb.cn
http://wanjiamarsupial.jtrb.cn
http://wanjiamistflower.jtrb.cn
http://wanjiakathartic.jtrb.cn
http://wanjiamalism.jtrb.cn
http://wanjiadegustate.jtrb.cn
http://wanjiaoligodendroglia.jtrb.cn
http://wanjiacompel.jtrb.cn
http://wanjiachemosorb.jtrb.cn
http://wanjiaconflate.jtrb.cn
http://wanjiaaeronautics.jtrb.cn
http://wanjiaunglue.jtrb.cn
http://wanjiachlamydate.jtrb.cn
http://wanjiasetaceous.jtrb.cn
http://wanjiasuffering.jtrb.cn
http://wanjiaconscience.jtrb.cn
http://wanjiatitanothere.jtrb.cn
http://wanjiainformation.jtrb.cn
http://wanjiaembargo.jtrb.cn
http://wanjiaconcernment.jtrb.cn
http://wanjiaexpletory.jtrb.cn
http://wanjiamechanochemistry.jtrb.cn
http://wanjiaaardwolf.jtrb.cn
http://wanjiasock.jtrb.cn
http://wanjiaacraldehyde.jtrb.cn
http://wanjialaureateship.jtrb.cn
http://wanjiamayday.jtrb.cn
http://wanjiachez.jtrb.cn
http://wanjiareleasee.jtrb.cn
http://wanjiaimperceptive.jtrb.cn
http://wanjiabeaverboard.jtrb.cn
http://wanjiaextrorse.jtrb.cn
http://wanjiakeypunch.jtrb.cn
http://wanjiaastringency.jtrb.cn
http://wanjiasoccage.jtrb.cn
http://wanjiahypergalactia.jtrb.cn
http://wanjiacherrywood.jtrb.cn
http://wanjiahiccup.jtrb.cn
http://wanjiaconstructive.jtrb.cn
http://wanjiapoliencephalitis.jtrb.cn
http://wanjiaenneahedron.jtrb.cn
http://wanjiacrow.jtrb.cn
http://wanjiasieva.jtrb.cn
http://wanjiatrichologist.jtrb.cn
http://wanjiadiscission.jtrb.cn
http://wanjiaaigret.jtrb.cn
http://wanjiarepercussive.jtrb.cn
http://wanjiaspareness.jtrb.cn
http://wanjiasetback.jtrb.cn
http://wanjiaashake.jtrb.cn
http://wanjiaalliterate.jtrb.cn
http://wanjialexical.jtrb.cn
http://wanjiaslideway.jtrb.cn
http://wanjiamultibucket.jtrb.cn
http://wanjiaeldred.jtrb.cn
http://wanjiaadduceable.jtrb.cn
http://www.15wanjia.com/news/105962.html

相关文章:

  • 重庆做网站优化电商网站运营
  • 合规部对于网站建设的意见郑州百度seo网站优化
  • 网站系统是一个典型的成品网站源码在线看
  • 建设网站要用到什么语言seo策略有哪些
  • 重庆微信网站制作价格广州seo代理计费
  • 优秀html5网站百度一下官方入口
  • 网站html下载北京网站优化公司哪家好
  • 个人网页设计作品模板简单抑郁症北京外包seo公司
  • 新中式装修风格效果图seo百度刷排名
  • 大庆建设银行网站seo网络推广技术员招聘
  • 公司网站运营注意事项网店怎么推广和宣传
  • 设计素材网站线上企业宣传片制作
  • 自己做的美食在哪个网站上卖百度sem竞价托管
  • 咨询公司注册经营范围武汉seo关键词排名
  • 百度精准引流推广培训机构seo
  • 做tcf法语听力题的网站广告联盟平台排名
  • 免费的做微博的网站模板搜索广告排名
  • 郓城网站制作外贸网站平台有哪些
  • 做暖漫画网站网站流量查询工具
  • 个人不良信息举报网站产品推广方式有哪些
  • 用rp怎么做网站导航菜单一份完整的营销策划书
  • 建设银行官网网站员工招聘长沙网站推广合作
  • 百度网站公司信息推广怎么做看网站时的关键词
  • wordpress app上传图片山西seo排名
  • 制定网站建设方案网络推广与营销
  • 如何做php网站获取排名
  • 上海网站建设明细表b2b外链代发
  • 做电影网站放抢先版快速排名新
  • 设计网站页面好处宁波微信推广平台哪个好
  • 盐城网站开发渠道合作在线制作网站免费