django中,用vue.js获取后端json数据并加载

本文示例了如何在Django项目中使用Vue.js从后端获取JSON数据,并在前端进行加载展示。通过Vue的`vue-resource`插件发起HTTP请求,接收到的数据被渲染到Vue实例的模板中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
    <script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.min.js"></script>
</head>
<body>
<div id="app">
  <ol>
    <li v-for="site in sites">
      [[ site.username ]]
    </li>
  </ol>
</div>

<script>
         var demo = new Vue({
            el: '#app',
            data: {
               sites: [],
               apiUrl: '/api/app/user/?format=json'
            },
            mounted: function() {
               this.getCustomers()
            },
            methods: {
               getCustomers: function() {
                  var _this = this;
                  this.$http.get(this.apiUrl)
                     .then((response) => {
                        _this.sites =response.data;
                        console.log(_this.sites)
                     })
               }
            },
                delimiters : ['[[', ']]'],
         })
</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值