简体   繁体   English

vue-for 不渲染对象 html

[英]vue-for doesn't render objects in html

Hello i want to create a live search table on my django app using the vuejs cdn.您好,我想使用 vuejs cdn 在我的 django 应用程序上创建一个实时搜索表。 On the POST side is working since it receives my API responses but when in it comes to render in vue-for it seems doesn't render and I only get is the header of table but the actual table body haven't appear in html page在 POST 端工作,因为它收到我的 API 响应,但是当它在vue-for它似乎没有呈现,我只得到表的 header,但实际的表体没有出现在 html 页面中

Here's my dashboard html file:这是我的仪表板 html 文件:

 <div id="app"class=" col-md-12 col-sm-12 py-3 px-4">
        <!--Text search-->
        <div class="input-group">
            <input @keyup="send_namerequest" v-model="search_query" type="text" class="form-control form-control-lg" placeholder="Search Bogus Client"
                aria-label="Recipient's username" aria-describedby="basic-addon2">
            <div class="input-group-append">
                <span class="input-group-text" id="basic-addon2"><i class="fas fa-search"></i></span>
            </div>
            <div id="eraser" class="input-group-append" @click="remove_search">
                <span class="input-group-text" id="basic-addon2"><i class="fas fa-eraser"></i></span>
            </div>
{%include "components/table.html"%}
        </div>

table.html表.html

<table v-show="true"id="recent" class="table p-0 w-0 table-lg table-responsive-sm table-striped table-bordered">
    <tbody >
            <tr v-for="client in resultsobj" :key="client.name"> 
                        <td ><#client.name#></td>
                        <td><#client.project.project_name#></td>
                        <td><#client.reason.reason_name#></td>
             </tr>
    </tbody>
</table>

app.js应用程序.js

var dash = new Vue({
    el: '#app',
    delimiters: ["<#", "#>"],
    data: {
        haveresults: false,
        search_query: '',
        resultsobj: [],
    },
    computed :{},
    ready: function(){},

    methods: {
        //  methods function
        remove_search : function(){
           
            this.search_query = "";
            this.haveresults = false;
        },

        async send_namerequest(){
            const res = await axios.post('/api/search/',{
                client_name : this.search_query,
            })
            .then(function(response){
                this.haveresults = true;
                this.resultsobj = (response.data);
                console.log(resultsobj)
            })
        }
        
        //end
    },
 
});

Update : After banging my head on the wall, I finally figured out by changing the this into app since it is the main initiator of new vue({})更新:在我的头撞墙之后,我终于通过将this更改为app来弄清楚,因为它是new vue({})的主要发起者

From this:由此:

 remove_search : function(){
           
            this.search_query = "";
            this.haveresults = false;
        },
        async send_namerequest(){
            const res = await axios.post('/api/search/',{
                client_name : this.search_query,
            })
            .then(function(response){
                this.haveresults = true;
                this.resultsobj = (response.data);
                console.log(resultsobj)
            })
        }
    },

Into this进入这个

 remove_search : function(){
           
            app.search_query = "";
            app.haveresults = false;
        },
        send_namerequest : function(){
            axios.post('/api/search/',{
                client_name : app.search_query,
            })
            .then(function(response){
                app.haveresults = true;
                app.resultsobj = response.data;
            })
        }
    },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM