vue ajax 不能绑定到 module

    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.js"></script>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>

    <nav class="navbar navbar-fixed-top" id="sidebar-wrapper" role="navigation">
      <ul class="nav sidebar-nav" v-for="msg in messages">
        <li>
          <i class="fa fa-fw fa-cog"></i>
          {{ msg.impdepname }}
        </li>
      </ul>
    </nav>
    
<script>
     var vm = new Vue({
        el: '#sidebar-wrapper',
        data: {
          messages: []
        },
        mounted: function () {
          $.ajax({
            url: 'http://localhost:61754/api/services/emisapp/b_emis_confsumimp/getlistsquery',
            data: { "depid": "99007" },
            type: 'POST',
            dataType: 'json',
            success: function (data) {
              console.log(data);
              this.messages = data.result;
              console.log(this.messages);
            },
            error: function (error) {
              console.log(error);
            }
          });
        }
      });
</script>


能在命令行输出数据,但是 v-for 绑定的时候报错

Uncaught ReferenceError: module is not defined    
moment-with-locales.min.js:1 

不知道是哪里出了问题。

阅读 2.4k
3 个回答

this

    mounted: function () {
          var _this= this;
          $.ajax({
            url: 'http://localhost:61754/api/services/emisapp/b_emis_confsumimp/getlistsquery',
            data: { "depid": "99007" },
            type: 'POST',
            dataType: 'json',
            success: function (data) {
              console.log(data);
              _this.messages = data.result;
              console.log(_this.messages);
            },
            error: function (error) {
              console.log(error);
            }
          });
        }
v-for="(msg,index) in messages" :key='index'

v-for这么写,同时要保证messages是个数组

看起来像是 moment 依赖报错了,可以注释掉引用 moment 的地方确认下

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题