Saad Shaikh
Saad Shaikh

Reputation: 179

Vuejs - Vue app render method with dynamic template (compiled) is throwing some error

I am trying to build a vuejs dashboard whose template is loaded from ajax request.

A sample structure of my dashboard template is

<div class="row">
    <div class="col-sm-6">
        <number-widget :option="option1"></number-widget>
    </div>
</div>

I tried following code but it's throwing

TypeError: Cannot read property '0' of undefined

        var vDashboard = new Vue({
            el: '#vue-dashboard',
            components:{ ... }
            data: {
                template: dashboardTemplate,
                _compile: null,
                option1: { ... }
            },
            render: function (h, b, v) {
                this._compile = Vue.compile(this.template).render;
                return this._compile();
            }
        });

Upvotes: 0

Views: 1085

Answers (1)

Saad Shaikh
Saad Shaikh

Reputation: 179

Ok, found out the issue. I was using Vue.compile().render it should be just Vue.compile()..

render: function (h, b, v) {
    var compile = Vue.compile(this.template);
    return h(compile);
}

Upvotes: 1

Related Questions