main.js 导入pinia
import App from './App'  
import { createSSRApp } from 'vue'  
import * as Pinia from 'pinia';  
const pinia = Pinia.createPinia()  
export function createApp() {  
  const app = createSSRApp(App)  
    app.use(pinia)  
  return {  
    app,  
        Pinia  
  }  
}
store/index.js
import {  
    defineStore  
} from "pinia"  
export const useCounterStore = defineStore('counter', {  
    state: () => ({  
        count: 10,  
    }),  
    actions: {  
        increment() {  
            this.count++  
        },  
    },  
})
App.vue
<script>  
    import { mapState } from 'pinia'  
    import { useCounterStore } from './store'  
    export default {  
        onShow: function() {  
            console.log(this.count)  
        },  
        computed: {  
            ...mapState(useCounterStore, ['count'])  
        }  
    }  
</script>  
                                    
            
            
            
            
孤竹 (作者)
APP线上的版本也必须 整包更新 吗
2024-05-13 17:16
DCloud_UNI_LXH
回复 孤竹: 是的
2024-05-14 14:40
DCloud_UNI_LXH
回复 孤竹: 尝试一个新的方案:
在
main.js中写入以下代码:一个可能的完整代码,比如:
注意: 详细测试一下 Pinia 的功能是否正常
2024-05-16 17:09
孤竹 (作者)
回复 DCloud_UNI_LXH: 没发现问题,可以使用
2024-05-21 14:58