###### tags: `VUE` VUEX 寫法 === ## 程式碼 因為我有 Layout.vue ,不然 Loading 效果因該是要加入 App.vue 以下是 Layout.vue ### store -> index.js ![](https://i.imgur.com/tYzn1O0.png) ### Layout.vue 可以刪除有關 isLoading,像是以下這些都可以先刪除 ```javascript data() { return { // isLoading: false, }; }, ``` 如果是 methods 可以改成 this.$store.state.isLoading, 從 store 取 isLoading ```javascript methods: { getProduct() { // 讀取所有商品資料 // this.isLoading = true; this.$store.state.isLoading = true; const api = `${process.env.VUE_APP_APIPATH}/api/${process.env.VUE_APP_UUID}/ec/products`; this.$http.get(api) .then((res) => { this.tempProduct = res.data.data; // this.isLoading = false; this.$store.state.isLoading = false; }) .catch(() => { this.$toast.error('資料讀取異常,請洽客服人員', { icon: 'fas fa-times' }); }); }, }, ``` #### 完成圖 ![](https://i.imgur.com/GoiLjbp.png) ### index.vue 其他內部的頁面都比照慣例,刪除 isLoading 做修改 ![](https://i.imgur.com/ogYlspT.png)