Vue.js does not display the template correctly

I work with Vue.js and Django. My goal is to display a list of the boxes I receive through the REST API.

Here is 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>

These messages are displayed correctly, but after receiving the GET request, the name remains on the page "% lt.% Bin.name%>. Using Vue-Inspector, I see that the component was generated correctly But the template does not update: enter image description here Any idea what I do wrogn ?

0
source share
1 answer

This is because in VueJS 2, delimiters are defined for each component, so you must also define them inside the component:

Vue.component('bin-detail', {
    delimiters: ['<%', '%>'],
    template: '#bin-detail',
    props: ['bin']
});
+4
source

Source: https://habr.com/ru/post/1675210/


All Articles