zoukankan      html  css  js  c++  java
  • vue 跨域访问http

    axios用法:

    npm install axios --save-dev

    2.导入:

    import axios from 'axios';

    3.使用($(form)需要先按装jQuery)

    axios.post('http://localhost:3000/users/zhuce',$(form).serialize())
        .then(function(res){
            console.log(res);
            alert(res.data);
        })
        .catch(function(err){
            console.log(err);
        })

    4.$(form)需要先按装jQuery

    npm install  jquery --save-dev 

    5.到build/webpack.base.conf.js中,

    导入:var webpack = require('webpack');
    最下面添加:

    plugins: [  
        new webpack.ProvidePlugin({  
             $:"jquery",  
             jQuery:"jquery",  
             "window.jQuery":"jquery"  
          })  
        ] 

    vue文件中无需导入,可直接使用$和jQuery

    1.安装

    npm install vue-resource --save-dev 

    2.main.js中

    Vue.use(require('vue-resource'));  //--------添加

    3.vue中使用

    callKa:function(event){
          this.$http.get('http://localhost:3000/',{}).then(function(data){
            alert(data.body);
          }).catch(function(err){
              alert('出错');
              for(let key in err){
                console.log(key+':'+err[key]);
              }
          })
        }
  • 相关阅读:
    Vue.js 父子组件间传递值
    Vue.js 单选绑定
    Vue.js 的v-for, v-html v-bind, v-show 实例
    Vue.js 表单input绑定
    Bootstrap tab
    Think PHP-- 笔记2
    MySql 修改登陆规则
    Think PHP--有趣的框架
    PHPStorm的xdebug配置
    伪类选择器
  • 原文地址:https://www.cnblogs.com/yu-hailong/p/8404517.html
Copyright © 2011-2022 走看看