yorickshan
12/24/2018 - 3:39 PM

JS库的三种使用方式

1、cdn

2、npm install

3、脚手架

以axios举例:

cdn

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

npm

npm install axios
npm install --save axios vue-axios

配置模板

import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
 
Vue.use(VueAxios, axios)

脚手架

Vue.axios.get(api).then((response) => {
  console.log(response.data)
})
 
this.axios.get(api).then((response) => {
  console.log(response.data)
})
 
this.$http.get(api).then((response) => {
  console.log(response.data)
})