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

网站title重复的后果外贸平台

网站title重复的后果,外贸平台,电商网站制作流程,网站首页设计怎么做在Vue 3 中有多种定义组件的方法。从选项到组合再到类 API,情况大不相同 1、方式一:Options API 这是在 Vue 中声明组件的最常见方式。从版本 1 开始可用,您很可能已经熟悉它。一切都在对象内声明,数据在幕后由 Vue 响应。它不是…

在Vue 3 中有多种定义组件的方法。从选项到组合再到类 API,情况大不相同

1、方式一:Options API

这是在 Vue 中声明组件的最常见方式。从版本 1 开始可用,您很可能已经熟悉它。一切都在对象内声明,数据在幕后由 Vue 响应。它不是那么灵活,因为它使用 mixin 来共享行为。


<script>
import TheComponent from './components/TheComponent.vue'
import componentMixin from './mixins/componentMixin.js'export 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>
<template><div class="wrapper"><TheComponent /><AsyncComponent v-if="object.variable" /><div class="static-class-name" :class="{ 'dynamic-class-name': object.variable }">Dynamic attributes example</div><button @click="emitEvent">Emit event</button></div>
</template><style lang="scss" scoped>
.wrapper {font-size: 20px;
}
</style>

方式二:Composition API

在 Vue 3 中引入了 Composition API。 目的是提供更灵活的 API 和更好的 TypeScript 支持。这种方法在很大程度上依赖于设置生命周期挂钩。


<script>
import {ref,reactive,defineComponent,computed,watch,
} from 'vue'import useMixin from './mixins/componentMixin.js'
import TheComponent from './components/TheComponent.vue'export 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')},
})
</script><template><div class="wrapper"><TheComponent /><AsyncComponent v-if="object.variable" /><div class="static-class-name" :class="{ 'dynamic-class-name': object.variable }">Dynamic attributes example</div><button @click="emitEvent">Emit event</button></div>
</template><style 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;
}
</script><script>
export default {name: "ComponentVue3",
};
</script><template><div class="wrapper"><TheComponent /><AsyncComponent v-if="object.variable" /><divclass="static-class-name":class="{ 'dynamic-class-name': object.variable }">Dynamic attributes example</div><button @click="emitEvent">Emit event</button></div>
</template><style scoped>
.wrapper {font-size: 20px;
}
</style>
http://www.yidumall.com/news/84419.html

相关文章:

  • 开封小吃网站建设佛山seo外包平台
  • wordpress手机适配模板北京seo外包公司要靠谱的
  • 南昌seo网站管理企业网站建设规划
  • 美国做汽车配件的网站洛阳seo网络推广
  • 潍坊建设部门管理网站电子商务网站建设论文
  • 网站url如何做优化百度统计收费吗
  • 校园二手交易网站开发背景天津百度推广公司地址
  • 怎么做网站的防盗链网站推广推广
  • 佛山seo管理seo日常工作
  • 国家开发大学网站作业怎么做seo平台
  • 厦门网站设计推广公司百度指数 移民
  • 在什么网站做知识禁毒竞赛百度指数数据分析平台
  • wordpress 花瓣seo招聘信息
  • 调用别人网站注册表单广告代运营
  • dreamweaver个人网站教程html家乡网站设计
  • 网站的改版怎么做seo查询平台
  • 联通专线做网站武汉网站推广
  • 直播网站开发要多久关键词优化包含
  • wordpress 编辑器 代码网络优化seo薪酬
  • 网站的线下推广怎么做国外搜索引擎大全
  • 制作网站app搜索引擎推广有哪些平台
  • 如何做网站美化深圳推广公司排行榜
  • 30岁转行做网站设计微信公众平台开发
  • 浙江建设厅继续教育网站同城推广有什么平台
  • 网游手游排行榜前十名长沙seo网络推广
  • 网站公司怎么找客户如何免费注册网站
  • 推荐大气的网站网站安全检测
  • 新手如何自己做网站制作网页用什么软件
  • 三门峡专业做网站公司10000个免费货源网站
  • 怎么删除ghost wordpressseo课程培训课程