T
T
thisuser2019-08-28 14:08:08
Vue.js
thisuser, 2019-08-28 14:08:08

Why doesn't it display the value of $root everywhere in the component?

I am a little familiar with Vue and have noticed strange behavior.
There is:

new Vue({
    el: '#app',
    created: function(){
      this.getCategories();
    },
    data:{
      content: 'что-то',
...
...

and a separate component:
var VueModal = Vue.extend ({
  template: `<div v-if="$root.modalContent">
                <div>
                  <input type="text" value="{{$root.content}}">
                </div>
                {{$root.content}}
              </div>
...
...

As a result, the output is like this:
<div>
  <div>
    <input type="text" value="{{$root.content}}">
  </div>
  что-то
</div>

Why is the value not rendered in value, but below everything is ok?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-08-28
@thisuser

First, interpolation with attributes does not work, value binding is done differently .
Secondly, you DO NOT need to touch $root. If you want to use an external value, pass it to the component as a parameter or get it from the storage .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question