Vue.js does not render correctly using template

2019-09-15 04:48发布

I am working with Vue.js and Django. My goal is to display a list of bins, which I get over a REST API.

Here's my JavaScript-Code:

Vue.component('bin-detail', {
template: '#bin-detail',
props: ['bin']
});

var app = new Vue({
    el: '#table',
    data: {
        message: "Hallo",
        bins: []
    },
    mounted: function() {
        $.get('/api/bins/', function (data) {
            app.bins = data.results;
        })
    },
    delimiters: ['<%', '%>']
});

And my HTML:

<div id="table">
    <h1><% message %></h1>
    <table class="table table-hover">
        <thead>
        <tr>
            <th>Name</th>
        </tr>
        </thead>
        <tbody>
            <tr v-for="bin in bins" is="bin-detail" :bin="bin"></tr>
        </tbody>
    </table>
</div>
<template id="bin-detail">
    <tr>
        <td>
            <% bin.name %>
        </td>
    </tr>
</template>

The message data is displayed correctly, but the name stays "<% bin.name %> on the rendered page after the GET request has been received. Using the Vue-Inspector I can see, that the component has been generated correctly But the template does not get updated: enter image description here Anyone an idea, what I'm doing wrogn?

1条回答
贼婆χ
2楼-- · 2019-09-15 05:13

It's because in VueJS 2 delimiters are defined per component, so you have to define them inside the component too:

Vue.component('bin-detail', {
    delimiters: ['<%', '%>'],
    template: '#bin-detail',
    props: ['bin']
});
查看更多
登录 后发表回答