這個不需要npm搭建腳手架安裝Vue,只需要簡單引入Vue的cdn連結,即可實現,透過引入Axios進行渲染資料到html頁面。
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue axios 渲染資料</title>
<script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
<style type="text/css">
[v-cloak] {
display: none;
}
</style>
</head>
<body>
<div id="app" v-cloak>
<h1>Vue Cdn Axios 渲染資料</h1>
<div v-for="site in info">
{{ site.title }}<br/>
{{ site.url }}<br/><br/>
</div>
</div>
<script type = "text/javascript">
new Vue({
el: '#app',
data () {
return {
info: null
}
},
mounted () {
axios
.get('./data.json')
.then(response => (this.info = response.data.list)) // 把結果集傳到info這個陣列
.catch(function (error) {
console.log(error);
});
}
})
</script>
</body>
</html>
data.json
{
"list": [
{ "title":"百度一下,你就知道","url":"www.baidu.com"},
{ "title":"讓天下沒有難做的生意","url":"www.taobao.com"},
{ "title":"再小的個體,也是一個品牌","url":"www.weixin.com"}
]
}
demo
http://likeyunba.com/demo/Vue...
Author:TANKING
Web:http://www.likeyunba.com/
Date:2020-11-11
WeChat:face6009