Skip to content

Instantly share code, notes, and snippets.

@pboivin
Created December 28, 2020 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pboivin/f8e14909755c2473a3c14638f044d32e to your computer and use it in GitHub Desktop.
Save pboivin/f8e14909755c2473a3c14638f044d32e to your computer and use it in GitHub Desktop.
Vue.js inline component test
<html>
<head>
<title>Vue.js inline component test</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
</head>
<body>
<div inline-component="{
name: 'Bob',
newName: '',
updateName() {
this.name = this.newName;
this.newName = '';
},
}">
<h1>Hello {{ name }}</h1>
<form @submit.prevent="updateName()">
<input type="text" v-model="newName">
<button type="submit">Update Name</button>
</form>
</div>
<script>
document.querySelectorAll('[inline-component]')
.forEach(el => {
let content = el.getAttribute('inline-component')
let data = new Function('return ' + content)
new Vue({ el, data })
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment