vue-cli填坑之路

Vue 引入jquery 

1,npm install jquery –save-dev

2,在build 找到 webpack.base.conf.js

       添加一个对象

       var webpack = require(‘webpack’);

       module.exports 最后添加

// 增加一个plugins

  plugins: [

    new webpack.ProvidePlugin({

      $: "jquery",

      jQuery: "jquery"

    })

  ]

3,在main.js中引入 $

import $ from ‘jquery’

 

 

 

如果不想使用规格检查:

在webpack.base.conf.js 中 注释掉包含eslint-loader的部分

 

vue模板中的table 中必须加<thead></thead>  <tbody></tbody>标准化

 

 

vue-cli 引入axios

一、npm 安装axios,文件根目录下安装,指令如下

 npm install axios --save-dev

二、修改原型链,在main.js中引入axios

import axios from 'axios'

接着将axios改写为Vue的原型属性,

Vue.prototype.$http=axios

这样之后就可在每个组件的methods中调用$http命令完成数据请求

三、在组件中使用

  1. methods: {
  2.       get(){
  3.         this.$http({
  4.           method:'get',
  5.           url:'/url',
  6.           data:{}
  7.         }).then(function(res){
  8.           console.log(res)
  9.         }).catch(function(err){
  10. console.log(err)
  11. })
  12. this.$http.get('/url').then(function(res){
  13. console.log(res)
  14. }).catch(function(err){
  15. console.log(err)
  16. })
  17. }    

19.}             

 

posted on 2018-07-17 17:41  vsmart  阅读(103)  评论(0编辑  收藏  举报