axios 和 element的使用


https://www.cnblogs.com/jflalove/p/11944483.html

https://blog.csdn.net/qq_40236722/article/details/88175015

 

axios的使用:

          

/**
 * 
 *    使用axios的步驟;
 *    第一步安裝 npm install --save axios vue-axios
      第二步,在mian.js中導入和配置,  (這是全局的axios)
    引入:
                     import axios from 'axios'

                     Vue.use(axios)
    配置 :
                     axios.defaults.baseURL="https://wd4363557576ckikwp.wilddogio.com/"
      第三步在你要使用的文件下引用axios
 
 
 */
    第二種配置
        import axios from 'axios' 配置axios

   與很多第三方模塊不同的是,axios不能使用use方法,轉而應該進行如下操作

 

引用axios

    axios 發送數據:

            

復制代碼
    const fromData={
             age:this.ruleForm.age,
             pass:this.ruleForm.pass
           }
           //發送數據
           axios.post('./axiosT.json',fromData)
           .then(res=>{//當數據發送成功時回調
           console.log("數據發送成功")
           console.log(res.data)
           
           })
           .catch((error)=>{
             console.log(error)
           })
復制代碼

     接受數據:

          

復制代碼
      mounted () {
            var that = this
            axios.get('/Produce.json')
            .then(function(response){
                console.log(response.data)
                that.produce=response.data
            })
       .catch(error => console.log(error))//檢查問題 :例如
  •                                                                API 不工作了;
  •                                                                請求發錯了;
  •                                                                API 沒有按我們預期的格式返回信息。
      }
復制代碼

         elementUi的使用:

        

復制代碼
vue.esm.js?efeb:628 [Vue warn]: Unknown custom element: <el-carousel> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

found in

---> <ElementUi> at src/components/elementUi.vue
       <App> at src/App.vue
         <Root>
復制代碼

      這個錯誤是因為沒有注冊組件在main.js里面

        

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';        //注冊組件
Vue.use(ElementUI);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM