zoukankan      html  css  js  c++  java
  • axios 和 element的使用

        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);
  • 相关阅读:
    善用js 异步引入,大幅提升vue站点加载速度,媲美大厂流畅性
    react hooks useState 赋值优化解决方案
    vue hash模式下的微信授权详解
    图片之间没加空格有间隙的解决方案
    React 父组件重新渲染,子组件不需要渲染的三种性能优化方式(PureComponent,memo,shouldComponentUpdate);
    uniapp历史模式history配置
    vue下请求数据地址的封装
    h5 下ios适配底部小黑条,简单解决方案,只需一步
    overflow:hidden 失效问题
    h5下数字,字母不换行的解决方案
  • 原文地址:https://www.cnblogs.com/jflalove/p/11944483.html
Copyright © 2011-2022 走看看