本文主要是介绍vue3使用mixins,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<template><div>{{ num }}___{{ fav }}</div><button @click="favBtn">改变值</button>
</template><script setup lang="ts">
import mixin from "../mixins/mixin";
let { num, fav, favBtn } = mixin();
defineExpose({ num, fav, favBtn });
</script><style></style>
../mixins/mixin.ts:
import { ref } from "vue";
export default function() {let num = ref(1);let fav = ref(false);let favBtn = () => {num.value += 1;fav.value = true;setTimeout(() => {fav.value = false;}, 2000)}return {num,fav,favBtn}
}
效果图:
这篇关于vue3使用mixins的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!