B
B
beduin012016-02-01 16:24:29
Vue.js
beduin01, 2016-02-01 16:24:29

How to pass data to a component in Vue.JS?

var guestContent = Vue.extend({
      template: `
        <p>Guest content</p>
          `,
        data: function () {
            myquestions: test();            
          }

        }
        );

...
Vue.component('guestcontent', guestContent);

What I want to do is, in this component, I want to output a list of questions from which I get from the `test()` function to the `myquestions` variable. The question is how to do it? And I don’t quite understand if I need rules for the output of these questions, and not just I will make a v-for (or whatever?) loop, then where can I describe them? Well, for example, that by clicking on such and such a question, something should happen ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hateyyyy, 2016-02-01
@hateyyyy

How to send data to parent using props in Vue?
A very similar question I once asked. A good example was dropped.
Data is passed to the component via the props property.
As for v-for, if I understand correctly, it might look like this

<ul>
    <li v-for = 'question in myquestions'  v-on:click = 'myMethods'>{{question}}</li
</ul>

In the component's methods property, you describe the function that you attach to the event, in this case 'myMethods'.
You will have a list of all the questions that came from the test function
Like so

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question