// useCount.ts
const useCount = () => {
const count = ref(0);
watch(count, () => {
console.log('count:', count.value);
});
return {
count
};
};
// helloWorld.vue
<template>
<button @
click="count++">count is: {{ count }}</button>
<button @
click="count2++">count is: {{ count2 }}</button>
</template>
<script lang="ts">
import { ref, defineComponent } from 'vue';
import { useCount } from "../compositions/count";
export default defineComponent({
name: 'HelloWorld',
props: {
msg: {
type: String,
required: true
}
},
setup: () => {
const { count } = useCount();
const { count: count2 } = useCount();
return { count, count2 };
}
});
</script>
你再试试?