Skip to content

Instantly share code, notes, and snippets.

@kai-kou
Created December 6, 2018 05:35
Show Gist options
  • Save kai-kou/9b5b613918e107ca23682982c75d9467 to your computer and use it in GitHub Desktop.
Save kai-kou/9b5b613918e107ca23682982c75d9467 to your computer and use it in GitHub Desktop.
Vue.jsでコンポーネントのイベント名をキャメルケースにすると反応しない
<html>
<body>
<div id="app">
<custom-component
:msg='msg'
v-on:hello-hoge="msg = 'OK!!!'"
v-on:helloHoge="msg = 'OK???'"
/>
</div>
<script type="text/x-template" id="custom-component">
<div>
<span>{{msg}}</span>
<button v-on:click="$emit('hello-hoge')">これはOK!</button>
<button v-on:click="$emit('helloHoge')">これはだめ!</button>
</div>
</script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
<script>
Vue.component("customComponent", {
props: ["msg"],
template: "#custom-component",
})
</script>
<script>
new Vue({
el: "#app",
data: {
msg: 'hoge'
},
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment