Error while rendering component

Asked

Viewed 369 times

2

The browser page is empty and the following error appears in the console:

Failed to resolve directive: ref

After commenting and uncommenting various parts of my code, I discovered that the page only works right when I comment on this line:

<h3>{{ status }}</h3>

I am using Vue.js 2. This status is computed:

computed: {
    status: function(){
        var count = 0;
        var lista = this.$refs.listaComponent;
        for(var i in lista.contas){
            if (!lista.contas[i].pago) {
                count++;
            }
        }
        return !count ? "Nenhuma conta a pagar." : "Existem " + count + " contas a pagar.";
    }
},

My HTML has this line:

<lista-component v-ref:lista-component></lista-component>

2 answers

1

Guilherme, I wanted to write as a comment my doubt but I have no points for this.. rs

Anyway, how did you declare this component? Did you remember to instantiate your Vue obj? You can send a link from Jsfiddle?

In the component statement, you need to instantiate your Vue obj, more or less like this:

var app = new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue!'
  }
})
  • I know what haha’s like, in the American OS I can’t comment either. It is right, because if I comment on that line that is in the component template it works right. So I came to the conclusion that the problem is in computed. And searching here seems that the problem has to do with v-ref. Maybe it’s because I’m adapting to routes?

  • I just noticed that the error has changed to: Failed to resolve directive: ref

1


In Vue.js 2.0 the directive v-ref turned into just ref, in accordance with the documentation.

This is the right way:

<lista-component ref="lista-component"></lista-component>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.