zoukankan      html  css  js  c++  java
  • 在js文件中引入vue实例

    应用场景:

    一般情况下,请求数据wx.request或者axios 请求数据,会新建一个api.js,进行封装。

    举例:

     wx.request(
         {
          header: {
            'content-type':'application/x-www-form-urlencoded'
          },
          url: baseUrl + config.url,
          method:config.method,
          data:{
            token:Vue.$store.state.loginUserInfo["userId"],
            ...config.params
          },
          success:(res)=>{ 
            if(res.data.code==116){
              wx.reLaunch({ url: "../logs/main" });
            }else if(res.data.code==0){
              return resolve(res.data)
            }else{
                wx.showToast({
                                 title: res.data.msg,
                                  icon: 'none'
                                    })
            }
            
          },
          fail:(err)=>{return reject(err)}
        })
    View Code

    这个情况下,需要获取到vue实例store上的数据,所以需要在js文件中,引入vue实例

    1.导出vue实例 在main.js中

    var vueDom=new Vue({
        store,
    }).$mount('#app')
    export default vueDom

    2.api.js(需要用vue实例的js)引入vue实例

    import Vue from '../main'

    3.使用

    Vue.$store.state.loginUserInfo["userId"]
  • 相关阅读:
    185. [USACO Oct08] 挖水井
    JavaEE Tutorials (9)
    vjudge A
    HDU 2089 不要62
    国庆 day 2 下午
    国庆 day 2 上午
    国庆 day 1 下午
    P2899 [USACO08JAN]手机网络Cell Phone Network
    洛谷 P1690 贪婪的Copy
    洛谷 P2209 [USACO13OPEN]燃油经济性Fuel Economy
  • 原文地址:https://www.cnblogs.com/GoTing/p/14690893.html
Copyright © 2011-2022 走看看