vue中的全局變量 this.$store.state 的取值與賦值


一、定義 全局變量

注:如果不在 store目錄下的 index.js 定義 則 在其它  ***.vue 頁面 代碼中賦值,其它頁面的這個全局變量,是不會變化的。

 

 store目錄下的 index.js

export default new Vuex.Store({

  state: {
    current_user_name:"未知",
    current_user_pwd:"未知",
    current_user_tel:"未知",
    current_isRegister:"分機 未注冊",
    pageId: 0,
    // pageList: ['分機監控', '外線監控', '分機管理', '通訊錄', '通話記錄', '修改密碼'],
    下面代碼略

二、賦值

在登陸頁 Login.vue

if (login_result == "true") { 
          this.$store.state.current_user_name=this.login.user;
          this.$store.state.current_user_pwd=this.login.password;
          this.$store.state.current_user_tel=this.login.number;
          this.$store.state.current_isRegister="分機未注冊";//已注冊
}

三、賦值 

在定時刷新頁  ****.vue

this.$store.state.current_isRegister="已注冊";

四、取值

 var str=this.$store.state.current_user_tel;
 <div class="name">{{$store.state.current_user_name}}</div>

注:如果不在 store目錄下的 index.js 定義 則 在其它  ***.vue 頁面 代碼中賦值,其它頁面的這個全局變量,是不會變化的。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM