Created
December 28, 2020 00:47
-
-
Save pboivin/f8e14909755c2473a3c14638f044d32e to your computer and use it in GitHub Desktop.
Vue.js inline component test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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