这个不需要npm搭建脚手架安装Vue,只需要简单引入Vue的cdn链接,即可实现,通过引入Axios进行渲染数据到html页面。
index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <!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
1 2 3 4 5 6 7 | { "list": [ { "title":"百度一下,你就知道","url":"www.baidu.com"}, { "title":"让天下没有难做的生意","url":"www.taobao.com"}, { "title":"再小的个体,也是一个品牌","url":"www.weixin.com"} ] } |
demo
Author:TANKING
Web:http://www.likeyun.cn/
Date:2020-11-11
WeChat:face6009