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

庆阳北京网站建设微信网页版二维码

庆阳北京网站建设,微信网页版二维码,wordpress 可视化,wordpress首页显示友情链接在Vue 3 中有多种定义组件的方法。从选项到组合再到类 API#xff0c;情况大不相同 1、方式一#xff1a;Options API 这是在 Vue 中声明组件的最常见方式。从版本 1 开始可用#xff0c;您很可能已经熟悉它。一切都在对象内声明#xff0c;数据在幕后由 Vue 响应。它不是…在Vue 3 中有多种定义组件的方法。从选项到组合再到类 API情况大不相同 1、方式一Options API 这是在 Vue 中声明组件的最常见方式。从版本 1 开始可用您很可能已经熟悉它。一切都在对象内声明数据在幕后由 Vue 响应。它不是那么灵活因为它使用 mixin 来共享行为。 script import TheComponent from ./components/TheComponent.vue import componentMixin from ./mixins/componentMixin.jsexport default {name: OptionsAPI,components: {TheComponent,AsyncComponent: () import(./components/AsyncComponent.vue),},mixins: [componentMixin],props: {elements: {type: Array,},counter: {type: Number,default: 0,},},data() {return {object: {variable: true,},}},computed: {isEmpty() {return this.counter 0},},watch: {counter() {console.log(Counter value changed)},},created() {console.log(Created hook called)},mounted() {console.log(Mounted hook called)},methods: {getParam(param) {return param},emitEvent() {this.$emit(event-name)},}, } /script templatediv classwrapperTheComponent /AsyncComponent v-ifobject.variable /div classstatic-class-name :class{ dynamic-class-name: object.variable }Dynamic attributes example/divbutton clickemitEventEmit event/button/div /templatestyle langscss scoped .wrapper {font-size: 20px; } /style方式二Composition API 在 Vue 3 中引入了 Composition API。 目的是提供更灵活的 API 和更好的 TypeScript 支持。这种方法在很大程度上依赖于设置生命周期挂钩。 script import {ref,reactive,defineComponent,computed,watch, } from vueimport useMixin from ./mixins/componentMixin.js import TheComponent from ./components/TheComponent.vueexport default defineComponent({name: CompositionAPI,components: {TheComponent,AsyncComponent: () import(./components/AsyncComponent.vue),},props: {elements: Array,counter: {type: Number,default: 0,},},setup(props, { emit }) {console.log(Equivalent to created hook)const enabled ref(true)const object reactive({ variable: false })const { mixinData, mixinMethod } useMixin()const isEmpty computed(() {return props.counter 0})watch(() props.counter,() {console.log(Counter value changed)})function emitEvent() {emit(event-name)}function getParam(param) {return param}return {object,getParam,emitEvent,isEmpty}},mounted() {console.log(Mounted hook called)}, }) /scripttemplatediv classwrapperTheComponent /AsyncComponent v-ifobject.variable /div classstatic-class-name :class{ dynamic-class-name: object.variable }Dynamic attributes example/divbutton clickemitEventEmit event/button/div /templatestyle scoped .wrapper {font-size: 20px; } /style使用这种混合方法需要大量样板代码而且设置函数很快就会失控。在迁移到 Vue 3 时这可能是一个很好的中间步骤但是语法糖可以让一切变得更干净。 方式三Script setup 在 Vue 3.2 中引入了一种更简洁的语法。通过在脚本元素中添加设置属性脚本部分中的所有内容都会自动暴露给模板。通过这种方式可以删除很多样板文件。 script setup import {ref,reactive,defineAsyncComponent,computed,watch,onMounted, } from vue;import useMixin from ./mixins/componentMixin.js; import TheComponent from ./components/TheComponent.vue; const AsyncComponent defineAsyncComponent(() import(./components/AsyncComponent.vue) );console.log(Equivalent to created hook); onMounted(() {console.log(Mounted hook called); });const enabled ref(true); const object reactive({ variable: false });const props defineProps({elements: Array,counter: {type: Number,default: 0,}, });const { mixinData, mixinMethod } useMixin();const isEmpty computed(() {return props.counter 0; });watch(() props.counter, () {console.log(Counter value changed); });const emit defineEmits([event-name]); function emitEvent() {emit(event-name); } function getParam(param) {return param; } /scriptscript export default {name: ComponentVue3, }; /scripttemplatediv classwrapperTheComponent /AsyncComponent v-ifobject.variable /divclassstatic-class-name:class{ dynamic-class-name: object.variable }Dynamic attributes example/divbutton clickemitEventEmit event/button/div /templatestyle scoped .wrapper {font-size: 20px; } /style
http://wiki.neutronadmin.com/news/307947/

相关文章:

  • 建设租房信息网站站长工具永久更新
  • 公司网站建设推广wordpress头像官网
  • 与客户沟通网站建设的技巧wordpress教程 chm
  • 注销网站 注销主体门户网站 特点
  • 个人网站引导页源码用dw制作html简单网页制作
  • 公司需要做网站需要什么流程淘宝客网站主题模版
  • 网站开发服务合同搜索引擎广告推广
  • 昆山小程序制作seo怎么才能做好
  • 建站官网郴州市建设局网站节能科
  • 中文 网站模板兴义网络推广
  • 交互性强的网站win7版本的wordpress
  • 做一个网站开发要多少钱wordpress获取菜单链接
  • 东莞建设通网站新乡外贸网站建设
  • 微信官方网站注册淄博市建设业协会网站
  • 做字素的网站ozon电商平台如何入驻
  • 金融网站策划方案wordpress 添加下载按钮
  • 怎么做网站实惠音乐网站怎么做无线增值业务
  • 域网站名分类企业年金辞职了怎么办
  • 建设个人网站的要求asp.net做网站系统
  • 网站后台密码忘记了怎么办 ftp进不去任县城乡建设局网站
  • 网站开发绪论网站帮助中心设计
  • 青岛网站建设¥青岛博采网络网站seo优化多少钱
  • 公司做二手网站的用意网站制作温州
  • jsp做网站de后台管理网加速器
  • 做二手车网站需要什么手续费大型网站建站公司
  • 济宁网站建设神华贸易公司取什么名字
  • 中国建设银行官网站招聘wordpress 查询数据
  • 寄生虫网站排名代做设计公司logo要多少钱
  • 西安有几家做网站国有企业投资建设项目
  • 郑州免费网站建设推荐企业门户网站建设