T
T
tantumus212020-10-21 09:29:58
Vue.js
tantumus21, 2020-10-21 09:29:58

What is the difference between these two ways of passing data to a component?

In the base Vue project, which is created automatically, you can see this line. But in the tutorials, I have never seen that data is passed to the component in this way. Only through . As far as I understand, in this way -> a string is simply passed to the msg variable . And it is needed in order to place the value of the parent variable into a variable that is used by the child component. So?
<HelloWorld msg="Welcome to Your Vue.js App"/>
v-bind
msg="Welcome"v-bind

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FinGanapre, 2020-10-21
@tantumus21

In order to pass something to the child component from the parent through props, you can always bind.
There is an abbreviated syntax:
:msg="'Welcome to Your Vue.js App'"
and a full one:
v-bind:msg="'Welcome to Your Vue.js App'"
The js expression is always quoted, i.e. to pass a string, you need to put more quotes. Just understand that you have normal js in quotes.
But you can do without bind, but this is rarely seen, because. most often a variable is passed to the component. Here is a tutorial to guide you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question