zoukankan      html  css  js  c++  java
  • vue搭建项目到axios&element ui引入(vue2.9.6)

    1,安装下载nodejs

     http://nodejs.cn/download/

    查看node&vue版本

    node -v
    vue -v
    

    2,npm下载vue&webpack&vue-cli脚手架

    npm init vue webpack vue-cli -g
    

    3,创建项目

    vue init webpack my-project(项目名)
    eslint y/n n
    jest y/n n
    e2e y/n n
    其他回车

    4,下载axios和element ui包

    npm init axios element ui
    

    5,引入axios和element ui包 

    improt axios form 'axios'
    import ElementUI from 'element-ui'
    import '../node_modules/element-ui/lib/theme-chalk/index.css'(引入element ui样式)
    Vue.prototype.axios=axios
    axios.defaults.baseURL = 'http://192.168.125.23/pfm/'(设置默认请求路径)
    Vue.config.productionTip = false 来关闭生产模式下给出的提示
    Vue.use(ElementUI)
    

      

    6,在组件中就可以直接使用this.axios()  

    1,
    this.axios({
    method:"get",
    url:"url",
    params:{id:1}
    }).then(res=>{}).cache(error=>{})
    // 如果是get请求的参数对象, 用的是params
    // 如果是post请求的参数对象,用的是data
    2,
    this.axios.get("/user",params:{ id:1})
    this.axios.post("/user",{id:1,name:"zs"})
    

      

      

  • 相关阅读:
    第四次作业
    第三次作业
    第二次作业。
    国庆作业。
    实验2-4
    实验2-3
    实验2-2
    实验2-1
    实验1-3
    实验 1-1
  • 原文地址:https://www.cnblogs.com/duhui/p/11784536.html
Copyright © 2011-2022 走看看