设置baseUrl

设置baseUrl


   /*axios.js*/ 
   import Axios from 'axios'

   export const baseUrl = process.env.NODE_ENV === 'development' ? 'http://192.168.0.101:3000/' : 'http://192.168.2.128:3000/'

   const axios = Axios.create({
     baseURL: baseUrl,
   })
   export default axios
   
  /*api请求*/ 
  import axios from '../axios'
  import {baseUrl} from "../axios"; (更多…)
Posted in: Vue

将常用的axios的方法定义为全局方法

  import axios from './axios'     // 引入axios
  import {defaultErrorHandler} from './axios'  // 引入默认错误处理

  /* 常用的query方法 */ 
  export function query(graphql, successHandler, errorHandler = defaultErrorHandler) {
    axios({
        method: 'post',
        url: 'graphql',
        data: graphql,
        headers: Object.assign({}, {
            'Content-type': 'application/graphql'
        })
    }).then(response => {
        successHandler(response.data.data)
    }).catch(e => {
        errorHandler(e)
    })
}

   /* 将常用的query方法注册为全局方法 */
   export default {
     install(Vue) {
        Vue.prototype.$query = query
    }
}
Posted in: Vue

web全屏方法

   // 全屏的方法
   toggleFullScreen(){
         if (screenfull.enabled) {
                 screenfull.toggle();
              }
      }


   // 初始设置全屏参数
   data() {
            return {
                isFullscreen: false
            }
        },
    mounted(){
            if (screenfull.enabled) {
                screenfull.on('change', () => {
                    this.isFullscreen = screenfull.isFullscreen
                });
            }
        },
Posted in: Vue


vuex 监控二维数组

当数组或者对象嵌套太深,数据无法驱动view,

 // 在组件层触发事件,
  this.$store.commit("checkTarget",{obj,index:this.commandIndex-1})
 // 在store中,
   import Vue from 'vue'
   checkTarget(state,obj){
        if(state.selectTargetList[obj.index]){
            state.selectTargetList[obj.index].map((v,k)=>{
               if(v.name === obj.obj.name){state.selectTargetList[obj.index].splice(k,1)}
            });
            state.selectTargetList[obj.index].push(obj.obj);
        }else{
            Vue.set(state.selectTargetList, obj.index, [obj.obj])   // 用于监控数据变化的set
        }
    }
Posted in: Vue


ˆ Back To Top