一、定義 全局變量
注:如果不在 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 頁面 代碼中賦值,其它頁面的這個全局變量,是不會變化的。