Saturday, March 11, 2023
HomeJavascriptTechniques in Vue - Grasping JS

Techniques in Vue – Grasping JS


Dec 20, 2022.

Techniques in Vue are specified in the approaches things.

 Vue.createApp( {
 information: () =>> ({ worth:  0} ),.
 approaches: {
getValue() {
 return  this worth;.
}
},.
 theme: '.
<< div>>.
<< div>> A feature that returns the worth of 'worth'<.
<< div> > {{getValue()}} <.
<.
'
} ). install(' #app');

Techniques are responsive

If your Vue theme utilizes an approach, as well as a worth that the approach counts on modifications, Vue will certainly re-render the theme.
As an example, the complying with code properly presents the existing worth, although worth is shown making use of an approach.

 Vue.createApp( {
 information: () =>> ({ worth:  0} ),.
 approaches: {
getValue() {
 return  this worth;.
},.
incrementValue() {
 this worth++;.
}
},.
 theme: '.
<< div>>.
<< div>> Adjustment the Worth of 'worth'<.
<< div>>.
<< switch @click=" incrementValue">> Click me<.
<.
<< div>> Present Worth: {{getValue()}} <.
<.
'
} ). install(' #example');

Techniques can be async

Merely include the async search phrase before your feature name to make it async.
Async approaches aren’t beneficial for showing in design templates, yet they are handy for making API demands when the customer clicks a switch or sends a type.

 Vue.createApp( {
 information: () =>> ({ reaction: "} ),.
 approaches: {
 async makeRequest() {
 const res =  wait for bring(' https://httpbin.org/get').
after that( res =>> res.json());.
 this reaction = res;.
}
},.
 theme: '.
<< div>>.
<< div>> Make an async demand<.
<< div>> The reaction: {{reaction}} <.
<< div>>.
<< switch @click=" makeRequest">> Click Me<.
<.
<.
'
} ). install(' #async')

When not to utilize Techniques

When it pertains to present or formatting associated reasoning, you ought to utilize calculated buildings
Techniques ought to just be utilized for occasion trainers as well as format in a v-for that depends on the state of the loophole.



Vue College has several of our preferred Vue.
video clip training courses. Their Vue.js Master Course strolls you via constructing an actual.
globe application, as well as does an excellent work of mentor you exactly how to incorporate Vue.
with Firebase.
Inspect it out!


Extra Vue Tutorials

RELATED ARTICLES

Most Popular

Recent Comments