Sorry guys I am new to node.js and was wondering whether we are allowed to use vue.js within an ejs file.
Yes, we can. Here is a scenario. Let's say you want to render a data
Object to ejs file, and you want this data
Object be accessible from VueJS.
First, in your controller, you have to render it as a JSON stringres.render("index", { data: JSON.stringify(data) });
in order to access it in your javascript code.
Then, in your VueJS code inside ejs file, you simply access it this way:
var app = new Vue({
el: '#app',
data: {
myData: JSON.parse('<%- data %>')
}
})
Note about <%-
tag in your VueJS code, it is necessary in order to output your data properly.
As VueJS
can be implemented into existing systems, you should be able to do so yes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With