axios: vue中的ajax,是用来前后端交互的
npm install axios 下载axios
<script src="js/vue.min.js" type="text/javascript" charset="utf-8"></script>
<!--vue链接在最前面-->
<script src="js/vue-router.js" type="text/javascript" charset="utf-8"></script>
<!--router再连接-->
<script src="js/axios.js" type="text/javascript" charset="utf-8"></script>
<!--axios最后连接·-->
建立数据库
[
{
"num":1,
"name":"apple",
"price":4,
"str":5,
"zong":20
},
{
"num":2,
"name":"pear",
"price":6,
"str":5,
"zong":30
},
{
"num":3,
"name":"orange",
"price":8,
"str":5,
"zong":40
}
]
<script type="text/javascript">
mounted:function(){
var son=this;
axios({
method:'get',//请求方式
url:'fruit.json'//数据库链接
}).then(function(参数){//请求成功
son.arr=ind.data
}).catch(function(参数){//请求失败
})
}
</script>
获取域址 http-server
安装获取npm install http-server -g