|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref } from 'vue'
|
|
|
|
|
import { ref , computed} from 'vue'
|
|
|
|
|
|
|
|
|
|
// 导入store,并获取store
|
|
|
|
|
import { useTestStore } from '@/store/test'
|
|
|
|
@ -7,8 +7,17 @@ const store = useTestStore()
|
|
|
|
|
|
|
|
|
|
// 改变store里面count的值
|
|
|
|
|
const addBtn =() =>{
|
|
|
|
|
// 方法1
|
|
|
|
|
store.count++
|
|
|
|
|
|
|
|
|
|
// 方法2
|
|
|
|
|
// store.setCount(++store.count)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 通过computed取值
|
|
|
|
|
const count = computed(()=>{
|
|
|
|
|
return store.count
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
@ -18,7 +27,7 @@ const addBtn =() =>{
|
|
|
|
|
<el-button @click="addBtn">+</el-button>
|
|
|
|
|
<div>
|
|
|
|
|
<h1>测试store是否引入成功</h1>
|
|
|
|
|
{{ store.count }}
|
|
|
|
|
{{ count }}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<el-icon>
|
|
|
|
|