鍍金池/ 問答/HTML/ vuex因為是單獨的執(zhí)行函數(shù)文件,如何讓本組件下使用的函數(shù)在單獨的文件下也能用?

vuex因為是單獨的執(zhí)行函數(shù)文件,如何讓本組件下使用的函數(shù)在單獨的文件下也能用?

methods:{
        loginSubmit(name) {
            const self = this;
            self.modal_loading = true;
            self.$refs[name].validate((valid) => {
                if (valid) {
                    let loginObj={
                        mobile: this.logPrefix+this.form1.mobile,
                        password: this.form1.password,
                    };
                    this.$store.dispatch('login',loginObj);
                  
                }
            })
        },
}

如上,在當前組件傳入登錄信息,調用action登錄,
我ui組件用的iview,我想登錄失敗的時候,調用iview的 this.$Message.error("") 彈出錯誤提示
但是這里不能直接用this. ,說找不到error方法,請問有什么辦法解決?

login({state,commit},payload) {
        axios.post('/login ',payload).then((res) => {
            Cookies.set('mobile', res.data.user.mobile);
            //                            Cookies.set('userId', res.data.user.id);
            Cookies.set('username', res.data.user.username);
            Cookies.set('token', res.data.token);
            Cookies.set('userType', res.data.userType);
            if(res.data.merchant){
                Cookies.set('auditStatus', res.data.merchant.status);
                Cookies.set('checkMessage', res.data.merchant.checkMessage);
                Cookies.set('merchantPhone', res.data.merchant.phone);
                Cookies.set('auditStatus', res.data.merchant.leaderPhone);
            }else{
                Cookies.set('auditStatus', "未提交審核");
            }
            if (res.data.userType === 'admin') {
                Cookies.set('access', 0);
            } else if(res.data.userType === 'user'){
                Cookies.set('access', 1);
            }else{
                Cookies.set('access', 2);
            }
            if(self.$route.query.redirect){
                //                                let redirect = decodeURIComponent(this.$route.query.redirect);
                let redirect = this.$route.query.redirect;
                self.$router.push(redirect);
            }else{
                self.$router.push('/');
            }
        }).catch((error) => {
            if(error.response.data.errorMassage){
                this.$Message.error(error.response.data.errorMassage);
            }else{
                this.$Message.error("登錄開小差了~請再試一遍");
            }
            self.modal_loading = false;
        });
回答
編輯回答
喜歡你

在樓上大神的指點下,已解決
解決辦法:
vuexjs文件下

import { Message } from 'iview'

使用的時候:

Message.error("登錄開小差了~請再試一遍");

2018年6月15日 16:25
編輯回答
失魂人

把message組件引用進來使用

this.$message這種方式是因為Vue.use了iview的組件

其他地方又不是不可以單獨引用

2017年9月2日 14:26