zoukankan      html  css  js  c++  java
  • vue项目中全局配置变量

    在项目中api管理需要用到全局变量,创建全局变量的方式也有很多。

    1.通过export default

      const BASEURL = "http://localhost:3333/"
      const URL = {
        getCategory:BASEURL+'category',
        getGoodsInfo:BASEURL+'getGoodsInfo'
      }
      export default URL
      在入口文件中引入

      import url from './api/api'

      Vue.prototype.URL=url;

    2.通过module.exports

    const BASEURL = "http://localhost:3333/"
    const URL = {
    getCategory:BASEURL+'category',
    getGoodsInfo:BASEURL+'getGoodsInfo'
    }

    module.exports = URL;

    在入口文件中引入Vue.prototype.URL=require('./api/api.js');

    其实以上两种都是Vue.prototype原型引入;

    3.通过node.js的global全局变量

    global.apiBase={}
    apiBase.baseUrl='http://localhost:3333/'

    apiBase.getBanner="/banners"
    apiBase.getcategory="/category"

    export default {
      apiBase
    };

    在路口文件中直接引入

    import  ApiBase from './api/api'

    4.通过VUEX的状态管理

       import Vue from 'vue';

       import Vuex from 'vuex';Vue.use(Vuex);

       const state = {}

      直接定义在state状态里面

    5.通过window对象设置

     

  • 相关阅读:
    Linux下安装Mysql
    mssql 查询效率
    查看apache是否安装及版本
    centos(linux)切换用户
    mysql操作命令(linux)
    远程连接MySql连不上1130
    JAVA环境配置
    SQLSERVER2012数据库还原
    ASP连接ACCESS数据库
    ODOO 常用widget
  • 原文地址:https://www.cnblogs.com/fangyinghua/p/9298628.html
Copyright © 2011-2022 走看看