Does your legacy app run on one of these?

Adding Vue.js to an Existing Project

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vuex"></script>

Fundamentals

const vueApp = new Vue({
el: '#vapp',
data: {
display: 'redbox'
}
})
<DOCTYPE html>
<html>
<head>
<title>Vue Demo #1: The Box App</title>
<meta charset='utf-8' />
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<h1>Vue Demo #1</h1>
<div id="vapp">
<p>Hello World.</p>
</div>
<!-- Our View App goes at the end of the document -->
<script>
const vueApp = new Vue({
el: '#vapp',
data: {
display: 'redbox'
}
})
</script>
</body>
</html>
<p>Hello World: {{ display }}</p>

Components!

Vue.component('ColoredBox', {
template: "<div class=\"box\"> - </div>"
})
<div id="vapp">
<colored-box class="red"/>
</div>
<style type="text/css">
.box {
height: 200px;
width: 200px;
text-align: center;
}
.red {
background-color: red;
}
.green {
background-color: green;
}
</style>

Conditional Display

<colored-box class="red" v-show="display == 'redbox'" />
<colored-box class="green" v-show="display == 'greenbox'" />
const vueApp = new Vue({
el: '#vapp',
data: {
display: 'redbox'
}
})
template: "<div class=\"box\"><button v-on:click=\"$emit('toggle')\">Toggle Now</button></div>"
<colored-box class="red" v-show="display == 'redbox'" v-on:toggle="toggleBox()"></colored-box>
<colored-box class="green" v-show="display == 'greenbox'" v-on:toggle="toggleBox()"></colored-box>
const vueApp = new Vue({
el: '#vapp',
data: {
display: 'redbox'
},
methods: {
toggleBox() {
this.display == 'redbox' ? this.display = 'greenbox' : this.display = 'redbox'
}
}
})
<DOCTYPE html>
<html>
<head>
<title>Vue Demo #1: The Box App</title>
<meta charset='utf-8' />
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style type="text/css">
.box {
height: 200px;
width: 200px;
text-align: center;
}
.red {
background-color: red;
}
.green {
background-color: green;
}
</style>
</head>
<body>
<h1>Vue Demo #1</h1>
<div id="vapp">
<colored-box class="red" v-show="display == 'redbox'"></colored-box>
<colored-box class="green" v-show="display == 'greenbox'"></colored-box>
</div>
<!-- Our View App goes at the end of the document -->
<script>
Vue.component('ColoredBox', {
template: "<div class=\"box\"><button v-on:click=\"toggleMe()\">Toggle Now</button></div>",
methods: {
toggleMe() {
this.$root.toggleBox()
}
}
})
const vueApp = new Vue({
el: '#vapp',
data: {
display: 'redbox'
},
methods: {
toggleBox() {
this.display == 'redbox' ? this.display = 'greenbox' : this.display = 'redbox'
}
}
})
</script>
</body>
</html>

Data Display and Modification

Vue.component('ColoredBox', {
template: "<div class=\"box\"><button v-on:click=\"toggleMe()\">Toggle Now</button><br><button v-on:click=\"clicks++\">Clickety Click</button><br>{{ clicks }}</div>",
data: function() {
return {
clicks: 0
}
},
methods: {
toggleMe() {
this.$root.toggleBox()
}
}
})
template: 
`<div class=\"box\">
<button v-on:click=\"toggleMe()\">Toggle Now</button>
<br>
<button v-on:click=\"clicks++\">Clickety Click</button>
<br>
{{ clicks }}
</div>`,
That is a punch card reader. That gentleman is either loading a program to run, or loading data for a running program, or both. This was a big time-saver for developers back when woolly mammoths roamed the steppes.

Other articles in the Vue series:

Building web applications since 1992. Crikey, that’s a long time.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store