The global function init() outputs a console log when the screen is loaded. However, clicking the child component button does not re-enable the init() function.
How can I call the global function init() when I click a button in my child's component?
App.vue (parent)
<template>
<div id="app">
<div id="nav">
<router-link :to="{name: 'home'}">Home</router-link> |
<router-link :to="{name: 'about'}">About</router-link>
</div>
<router-view></router-view>
</div>
</template>
<script>
import './assets/css/style.css'
import './assets/js/commmon.js'
export default {
}
</script>
Home.vue (child)
<template>
<div>
<a href="#" id="btn_link">Home Button</a><br><br>
</div>
</template>
main.js
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
Vue.config.productionTip = false
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
router.js
import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
import About from './views/About.vue'
Vue.use(Router)
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{ path: '/', name: 'home', component: Home},
{ path: '/about', name: 'about', component: About},
]
})
function init() {
console.log('load inti()')
}
init();
$('#btn_link').click(function(){
init();
});