问题
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