close

Global.vue
要共用的全域參數

<script>
const _token = "";
const userid = "";
export default {
  _token, //使用者地址
  userid,
};
</script>

使用方式2:
直接在需要使用的檔案 引入全域性變數模組
看範例

<template>
<div>{{ token }}</div>
</template>
<script>
import global_ from '../config/Global'//引用模組進來
export default {
data () {
return {
token:global_.token,
}
}
}
</script>

使用方式2:
在入口檔案 main.js,
將Global.vue 掛載至 Vue.prototype

import global_ from './config/Global'
Vue.prototype.GLOBAL = global_//掛載到Vue例項上面

//直接通過this訪問全域性變數。

<template>
<div>{{ token }}</div>
</template>
<script>
export default {
data () {
return {
token:this.GLOBAL.token,
}
}
}
</script>
arrow
arrow
    文章標籤
    vue
    全站熱搜

    nL 發表在 痞客邦 留言(0) 人氣()