我有一個員工表。每個員工都有一個角色,我試圖用單選按鈕來過濾(例如單選按鈕管理員或superadmin)。Vue.js在另一個組件的組件中使用變量
如何在另一個組件中使用組件內的變量?現在我有這樣的:
<template id="searchemployees">
<div class="form-group">
<label class="col-md-2 control-label">Filter</label>
<div class="col-md-10">
<div class="radio radio-primary">
<label>
<input type="radio" name="intern" id="intern" value="intern" v-model="selectedrole"/>
Toon alles
</label>
</div>
<div class="radio radio-primary">
<label>
<input type="radio" name="employee" id="employee" value="employee" v-model="selectedrole">
Stagiaire
</label>
</div>
</div>
</div>
</template>
<template id="employees">
<table class="table">
<thead>
<tr>
<th>Logo</th>
<th>Bedrijfsnaam</th>
<th>Plaats</th>
</tr>
</thead>
<tbody>
<tr class="table-row-link" data-href="" v-for="employee in list | role selectedrole">
<td><img class="img-circle-company" src=""/></td>
<td>@{{ employee.role.RoleName }}</td>
<td>@{{ employee.LastName }}</td>
</tr>
</tbody>
</table>
</template>
<script>
Vue.config.debug = true;
Vue.filter('role',function(value,role)
{
if(!role || 0 === role.length)
{
return value;
}
return value.filter(function(item) {
return item.role.RoleName == role
});
});
Vue.component('searchemployees', {
template: '#searchemployees'
});
Vue.component('employees', {
template: '#employees',
props:['list'],
created() {
this.list = JSON.parse(this.list);
}
});
new Vue({
el: 'body'
});
</script>
在我#searchemployees
它需要正確的選擇的角色。但是我怎樣才能在#employees
中爲我的過濾器使用它?
三江源
你想在你的組件之間傳遞什麼變量?我假設它是道具:['list']'? – 10000RubyPools
@ 10000RubyPools其實我想列表項是全球性的,所以我可以從任何組件訪問它。 – Jamie