>  기사  >  웹 프론트엔드  >  Ajax와 함께 Vue.js를 사용하여 데이터를 바인딩하는 방법

Ajax와 함께 Vue.js를 사용하여 데이터를 바인딩하는 방법

不言
不言원래의
2018-07-11 17:42:571947검색

이 글은 주로 Vue.js와 ajax로 데이터를 바인딩하는 방법을 소개합니다. 이제 특정 참고 가치가 있습니다. 필요한 친구들이 참고할 수 있습니다.

        <script>
            new Vue({
                el: &#39;#vue-menu3&#39;,      //p的id
                data: {                    : ""    //数据,名称自定
                },
                created: function () { //created方法,页面初始调用    
                    var url = "GetData.ashx";
                    this.$http.get(url).then(function (data) {   //ajax请求封装
                        var json = data.body;
                        var jsonObj = eval(&#39;(&#39; + json + &#39;)&#39;);
                       // console.info(jsonobj);
                        this.all = jsonObj;
                    }, function (response) {     //返回失败方法调用,暂不处理
                        console.info(response);
                    })
                }
            });
        </script>

페이지 코드

        <p id="vue-menu3">
            <table class="table table-striped" >
                <caption>借阅书籍列表</caption>
                <thead>
                    <tr>
                        <th>书籍编号{{all.id}}</th>
                        <th>书名</th>
                        <th>管理人员</th>
                        <th>借阅时期</th>
                        <th>归还时间</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="value in all.libraryBooks">
                        <td>{{value.bookId}}</td>
                        <td>{{value.name}}</td>
                        <td>{{value.chargePerson}}</td>
                        <td>{{value.borrowTime}}</td>
                        <td>{{value.returnTime}}</td>
                    </tr>
                </tbody>
            </table>
        </p>

다음은 데이터입니다. 바인딩 따로 결정

      new Vue({
                el: &#39;#vue-menu3&#39;,      //p的id
                data: {                    libraryInfo: ""    //数据,名称自定
                },
                created: function () { //created方法,页面初始调用    
                    var url = "GetData.ashx";
                    this.$http.get(url).then(function (data) {   //ajax请求封装
                        var json = data.body;
                        var jsonobj = eval(&#39;(&#39;+json+&#39;)&#39;);
                        console.info(jsonobj);
        
                        //我的json数据参考下面
                        this.libraryInfo = jsonobj.libraryBooks;
                    }, function (response) {     //返回失败方法调用,暂不处理
                        console.info(response);
                    })
                }
            });

 페이지 코드

   <p id="vue-menu3">
            <table class="table table-striped">
                <caption>借阅书籍列表</caption>
                <thead>
                    <tr>
                        <th>书籍编号</th>
                        <th>书名</th>
                        <th>管理人员</th>
                        <th>借阅时期</th>
                        <th>归还时间</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="value in libraryInfo">
                        <td>{{value.bookId}}</td>
                        <td>{{value.name}}</td>
                        <td>{{value.chargePerson}}</td>
                        <td>{{value.borrowTime}}</td>
                        <td>{{value.returnTime}}</td>
                    </tr>
                </tbody>
            </table>
        </p>

 꼭 vue-resource.js와 vue.min.js

를 인용해야 합니다. 위 내용은 모두의 학습에 도움이 되기를 바랍니다. 더 많은 관련 내용을 보려면 PHP 중국어 넷을 주목하세요!

관련 추천:

Vue 문자열 템플릿 소개

JavaScript에서 스택을 구현하는 방법

위 내용은 Ajax와 함께 Vue.js를 사용하여 데이터를 바인딩하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.