[英]How can i pass parametres from vue function in component?
我必須用參數調用 function 但我沒有找到解決我問題的正確方法。 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>
您在模板中使用了內聯事件處理程序 ( 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.