Activate method on router link click in Vue

余生长醉 提交于 2021-01-27 05:33:15

问题


I am working on account removal on a Chrome extension and I have the following button:

<button @click="remove" id="button_remove" class="btn btn-default" style="float: right;">Remove Account</button>

JS

methods:{
    remove(event){
       app.removeAccountData(url,apikey);
    }
},

I also have this router-link:

<router-link :to="{ name: 'RemovedWId', params: { accountid: chosenAccount.apikey}}" text="delete_account"><span class="glyphicon glyphicon-trash" aria-hidden="true" style="margin-top: 2px; cursor: pointer;"></span> Remove Account</router-link>

Is there a way to use the router-link with the JS function?


回答1:


Since <router-link> is a component wrapper around <a>, we'll need to use the .native modifier to properly receive the event:

<router-link @click.native="remove" to="/remove">Remove</router-link>

demo



来源:https://stackoverflow.com/questions/52229947/activate-method-on-router-link-click-in-vue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!