Vue中混入的作用是分發(fā)組建中可復(fù)用的功能
新建mixins文件夾,新建mixins.ts文件
import { ref } from 'vue';
export default function () {
const num = ref(0);
const fav = ref(false);
const fvbtn = () => {
num.value += 1;
fav.value = true;
setTimeout(() => {
fav.value = false;
}, 3000);
};
return {
num,
fav,
fvbtn,
};
}
在文件中引用文章來源:http://www.zghlxwxcb.cn/news/detail-536975.html
<!--
* @Author: wangyf 1758985226@qq.com
* @Date: 2023-07-04 17:32:24
* @LastEditors: wangyf 1758985226@qq.com
* @LastEditTime: 2023-07-05 08:57:17
* @FilePath: \fast-vue3\src\pages\mixinsVue\index.vue
* @Description: 這是默認(rèn)設(shè)置,請?jiān)O(shè)置`customMade`, 打開koroFileHeader查看配置 進(jìn)行設(shè)置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
<div>
<h1>混入</h1>
{{ num }}<br />
<button @click="fvbtn">
{{ fav ? '收藏中...' : '收藏' }}
</button>
<hr />
<A />
</div>
</template>
<script setup>
import A from './A.vue';
import mixin from '../mixins/mixins.ts';
const { num, fav, fvbtn } = mixin();
</script>
<style></style>
注意:二者的函數(shù)復(fù)用,但是數(shù)據(jù)不共享文章來源地址http://www.zghlxwxcb.cn/news/detail-536975.html
到了這里,關(guān)于vue3混入mixins的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!