【问题标题】:How can i access $toast in Nuxt vuex store我如何在 Nuxt vuex 商店中访问 $toast
【发布时间】:2020-12-07 06:01:23
【问题描述】:

我已在我的应用程序中安装了 @nuxtjs/toast 并正常工作。

我想在发送操作后显示祝酒词。 如何在 vuex 商店的模块中的操作中访问 $toast

PS:我正在使用带有 typescript 的 Nuxt,从 intellisense 看来我只能访问 $router 和 $axios。

export const actions: ActionTree<ProfileState, RootState> = {
async updateProfile({ }, user) {
    console.log(user);
    const newUserObj = await this.$axios.post("/me/update", user).then(res => res.data.data);

    console.log(newUserObj);
    // this.$toast.info("Hello");

    // commit('LOAD_NEW_USER', newUserObj);
},
}

【问题讨论】:

    标签: typescript vuex nuxt.js toast


    【解决方案1】:

    首先,让我们修正你的行为

    async updateProfile({commit}, user) {
        return new Promise(async(resolve,reject)=>{
          try {
            const newUserObj = await this.$axios.$post("/me/update", user)
            commit('SET_USER',newUserObj)
            resolve(newUserObj)
            
          } catch (error) {
            reject(error)
          }
         
        })
      },
    
    

    展示吐司-

    commit('SET_USER',newUserObj) 行下方尝试this.app.$toast

    【讨论】:

    • 谢谢。工作就像一个魅力,并指出重构
    • @useruser8254635 如果我想在突变中访问它怎么办?我该怎么办?
    • 我想它的工作方式与上面提到的相同,但你不应该从 vuex 设置 toast。在您的操作承诺解决或拒绝后,在页面或组件中显示 toast。
    • @useruser8254635 显然它的工作方式不同。而且我没有用它来烤面包。我正在尝试访问这个。$auth 我正在使用@nuxt/auth
    猜你喜欢
    • 2018-12-19
    • 2018-11-23
    • 2020-08-25
    • 2021-09-24
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 2021-01-23
    • 2017-12-05
    相关资源
    最近更新 更多