// plain
Vue.js is a popular UI library for developing web applications. It provides a powerful and easy-to-use API for creating user interfaces. Here's an example of how to use Vue.js to create a simple web application:
<div id="app">
<h1>{{ message }}</h1>
<button @click="changeMessage">Change Message</button>
</div>
<script>
new Vue({
el: '#app',
data: {
message: 'Hello World!'
},
methods: {
changeMessage: function() {
this.message = 'Goodbye World!'
}
}
})
</script>
This code will create a web page with a heading that reads "Hello World!" and a button that, when clicked, will change the heading to "Goodbye World!".
The code consists of three parts:
- The HTML: This defines the structure of the page. In this example, it creates a
div
element with anh1
and abutton
. - The Vue instance: This is where the Vue.js code is written. It creates a new Vue instance and binds it to the
#app
element. It also sets up thedata
andmethods
for the instance. - The JavaScript: This is the code that runs when the button is clicked. It changes the
message
in thedata
to "Goodbye World!".
For more information on how to use Vue.js to develop web applications, you can check out the Vue.js documentation.
onelinerhub: How can I use the Vue.js UI library to develop a web application?