cdn引入vue 在html页面中,用axios请求接口

发布时间 2023-03-28 15:57:28作者: 夏小夏吖
<!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('接口路径')
      .then(response => (this.info = response.data.list)) // 把结果集传到info这个数组
      .catch(function (error) {
        console.log(error);
      });
  }
})
</script>
</body>
</html>