MOCKSTACKS
EN
Questions And Answers

More Tutorials









VueJs Hello World Program


JSX is not meant to be interpreted by the browser. It must be first transpiled into standard Javascript. To use JSX you need to install the plugin for babel babel-plugin-transform-vue-JSX
Run the Command below:

npm install babel-plugin-syntax-jsx babel-plugin-transform-vue-jsx babel-helper-vue-jsx-mergeprops --save-dev

and add it to your .babelrc like this

{
 "presets": ["es2015"],
 "plugins": ["transform-vue-jsx"]
}

Sample code with VUE JSX:


import Vue from 'vue'
import App from './App.vue'
new Vue({
 el: '#app',
 methods: {
 handleClick () {
 alert('Hello!')
 }
 },
 render (h) {
 return (
<div>
 <h1 on-click={this.handleClick}>Hello from JSX</h1>
 <p> Hello World </p>
 </div>
 )
 }
})

By using JSX you can write concise HTML/XML-like structures in the same file as you write JavaScript code.

Handling User Input


VueJS can be used to easily handle user input as well, and the two way binding using v-model makes it really easy to change data easily.
HTML :
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<div id="app">
 {{message}}
<input v-model="message">
</div>

JS
new Vue({
 el: '#app',
 data: {
 message: 'Hello Vue.js!'
 }
})


It is very easy to do a two-way binding in VueJS using v-model directive.


Conclusion

In this page (written and validated by ) you learned about VueJs Hello World Program . What's Next? If you are interested in completing VueJs tutorial, your next topic will be learning about: VueJs Components.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.