我必須用引數呼叫一個函式,但我沒有找到解決我的問題的正確解決方案。NavigateTo 應該將一個字串值傳遞給我的索引以切換它并導航到正確的組件(沒有 vue 路由器)。
主頁.js
Vue.component('Home', {
props: ['visible','logged'],
data: function (){
return{
}
},
template: <a class="btn btn-primary display-4" on:click="NavigateTo(accedi)">Accedi</a>\n'
(only the button that call the function,i will post the rest of the code only if necessary)
methods:{
NavigateTo:function(destination){
this.$emit('transit-inner', destination);
}
}
});
索引.js
<section id="Home" style="margin-top: 60px">
<Home v-bind:visible="visible" v-bind:logged="session_info" v-on:transit-inner="goto()"></Home>
<script>
new Vue({
el: '#Home',
data:{
visible: routes.visible_home,
session_info: routes.status_session
},
methods:{
goto: function (destination){
alert(destination);
}
}
})
</script>
</section>
uj5u.com熱心網友回復:
您goto()在模板中使用了行內事件處理程式 ( ):
<Home v-bind:visible="visible" v-bind:logged="session_info" v-on:transit-inner="goto()"></Home>
你有兩個選擇:
一、去掉 ()
<Home v-bind:visible="visible" v-bind:logged="session_info" v-on:transit-inner="goto"></Home>
或者,$event如果使用行內處理程式,請提供特殊變數
<Home v-bind:visible="visible" v-bind:logged="session_info" v-on:transit-inner="goto($event)"></Home>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/377026.html
標籤:javascript 功能 Vue.js 函数参数
下一篇:vue從組件更改div
