ListComponent.vue
<button class="add">Button</button>
home.html
$('.add').on('click',function() {
alert('Add');
});
Alert not show. How Can I get that class?
You can directly do it in Vue, but if you wanted to use jQuery then you can write the jQuery code in the mounted or created hook. Also you can use the jQuery code in the methods as well.
new Vue({
el: "#app",
mounted () {
$('.add').on('click',function() {
alert('Add');
});
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="app">
<button class="add">Button</button>
</div>
Don't use jquery .. it's easy to solve in vuejs
<button @click="alert('Add')">Button</button>
.add selector anywhere on the page at arbitrary moment of time is the way to make the app buggy, leaky and hard to maintain, something that jQuery code is famous for.alert=('Add') is a mistake.