cnpm i node-sass@4.14.1 cnpm i sass-loader@7.3.1 --save-dev
vue 中引用Echarts
在main.js中引入
//引入Echarts
import echarts from "echarts"
Vue.prototype.$echarts = echarts
创建一个 Vue 页面对 Echarts 柱状图进行一个简单的展示
<template>
<div class="EchartPractice">
<div id="main"></div>
</div>
</template>
<script>
export default {
name: "EchartPractice",
methods:{
drawChart() {
let myEchart = this.$echarts.init(document.getElementById("main"));
let option = {
title:{
text:"Vue中使用Echarts小练习"
},
tooltip:{},
legend:{
data:["销量"]
},
xAxis:{
data: ["苹果","香蕉","橘子","葡萄",]
},
yAxis:{},
series:[{
name:'销量',
type:"bar",
data:[50,60,45,30,]
}]
};
myEchart.setOption(option);
}
},
mounted() {
this.drawChart();
}
}
</script>
<style scoped>
#main {
width: 600px;
height:400px;
margin: auto;
margin-top: 100px
}
</style>
axios基本使用
get请求获取数据
axios({
method:'Get',
url:'https://openapi.dataoke.com/api/goods/get-goods-list'
}).then(response => {
console.log(response)
})
post发送数据
axios({
method:'POST',
url:'https://openapi.dataoke.com/api/goods/get-goods-list',
// 请求体
data:{
msg:"今天天气不错"
}
}).then(response => {
console.log(response)
})
request请求数据
axios.request({
method:'GET',
url:'https://openapi.dataoke.com/api/goods/get-goods-list'
}).then(response =>{
console.log(response)
})
post增加
axios.defaults.method = 'GET'; //设置默认请求为get
axios.defaults.baseURL = 'https://openapi.dataoke.com/api/goods' //设置基础URL
axios.request({
url:'/get-goods-list',
}).then(response =>{
console.log(response)
})
请求拦截器,响应拦截器
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
console.log('请求拦截器 - 成功')
return config;
}, function (error) {
// 对请求错误做些什么
console.log('请求拦截器失败')
return Promise.reject(error);
});
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
// 对响应数据做点什么
console.log('响应拦截器 - 成功')
return response;
}, function (error) {
// 对响应错误做点什么
console.log('响应拦截器 失败')
return Promise.reject(error);
});