[Vuejs]-Vue2 @click on element outside of "el"

0👍

Nothing happens of course, as Vue is only initialised on the #app div:

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
    <button class="add" @click="click">Press works</button>
</div>
    
<div id="otherapp">
    <button class="add" @click="click">Press nothing happens</button>
</div>
<script>
var app = new Vue ({
    el: "#app",
    methods: {
      click()
       {
       alert("click triggered")
      }
    }
})
</script>

Leave a comment