美文网首页Django
Vue 添加全局变量

Vue 添加全局变量

作者: 凤箫之舞 | 来源:发表于2020-05-28 16:29 被阅读0次
  1. 先创建一个config.vue文件
<script>
    const host_url = 'http://127.0.0.1:8000/';
    const img_upload_url = 'http://127.0.0.1:8000/uploadImg/';
    const img_upload_rich_url = 'http://127.0.0.1:8000/ueUploadImg/';

    export default {
        host_url,
        img_upload_url,
        img_upload_rich_url,
    }
</script>

2.在main.js里面引入
import config from './components/common/config.vue';
Vue.prototype.config = config;

3.在页面直接使用
如:this.config.host_url

相关文章

网友评论

    本文标题:Vue 添加全局变量

    本文链接:https://www.haomeiwen.com/subject/rdyaahtx.html