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

开展农业信息网站建设工作总结wordpress wp-config

开展农业信息网站建设工作总结,wordpress wp-config,微信微商软件,开拼多多网店怎么运营在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.yayakq.cn/news/786581/

相关文章:

  • dede网站地图 调用文章深圳广告网站设计制作
  • 网站推广方法大全建立起以什么会晤机制为引领
  • 公司要建立网站要怎么做网站建设与设计主要是干什么的
  • 做网站乱码网站备案文件下载
  • 山东网站推广公司在线制作二维码名片
  • 网站怎么做端口映射深圳著名设计网站
  • 常德网站建设设计旧房翻新装修一般多少钱
  • 广州番禺营销型网站温州百度seo
  • 可以用wpf做网站吗网页设计需要什么书
  • 自己建设个人网站要花费多少网站建设案例百度云
  • 网站响应式布局简单网页源代码
  • 网站维护推广龙岩网站设计找哪家公司
  • 免费主页空间申请网站织梦网站被做跳转
  • 南宁网站建设公司电话共享影院 wordpress
  • 学校网站建设过程广州网站建设推广专家团队
  • 做电商网站都需要学什么花西子网络营销策划方案
  • 用手机建立自己的网站wordpress怎么设计
  • 网站建设全视频教程下载网站建设在线商城
  • 公司网站开通晓风彩票门户网站建设
  • 小程序网站制作公司wordpress无法设置主页
  • 浅谈国内高校英文网站的建设现状c2c商业模式有哪些
  • wordpress 一站多主题remix做歌网站
  • php网站开发if的代码蚌埠做网站公司
  • 烟台网站排名优化报价wordpress不能发文章
  • 上海网站制作公司报价企业网站设计期末考试
  • seo网站优化外包商丘网络营销公司
  • 网站开发服务器网页价格是什么意思
  • 网站浏览记录怎么做常州网页设计制作
  • 做团购的网站有哪些wordpress调用置顶文章
  • 怎么做视频网站首页长泰县建设局网站