- Vue.js 2.x by Example
- Mike Street
- 95字
- 2021-07-02 20:00:32
Creating the component
As with the team-member component, declare a new Vue.component() in your JavaScript, referencing a template ID of #filtering-template. Create a new <script> template block in your view and give it the same ID. Replace the filtering form in the view with a <filtering> custom HTML template and put the form inside your filtering-template script block.
Your view should look like the following:
<p id="app">
<filtering></filtering>
<table>
<template v-for="inpidual in people">
<team-member v-bind:person="inpidual" v-
bind:filter="filter" v-
bind:statusfilter="isActiveFilterSelected()"> </team-member>
</template>
</table>
</p>
<script type="text/x-template" id="filtering-
template">
<form>
<label for="fiterField">
Field:
<select v-on:change="changeFilter($event)" id="filterField">
<option value="">Disable filters</option>
<option value="isActive">Active user</option>
<option value="name">Name</option>
<option value="email">Email</option>
<option value="balance">Balance</option>
<option value="registered">Date
registered</option>
</select>
</label>
<label for="filterQuery" v-show="this.filter.field
&& !isActiveFilterSelected()">
Query:
<input type="text" id="filterQuery" v-
model="filter.query">
</label>
<span v-show="isActiveFilterSelected()">
Active:
<label for="userStateActive">
Yes:
<input type="radio" v-bind:value="true" id="userStateActive" v-model="filter.query">
</label>
<label for="userStateInactive">
No:
<input type="radio" v-bind:value="false"
id="userStateInactive" v-model="filter.query">
</label>
</span>
</form>
</script>
<script type="text/x-template" id="team-member-
template">
// Team member template
</script>
And you should have the following in your JavaScript:
Vue.component('filtering', {
template: '#filtering-template'
});
推薦閱讀
- 簡單高效LATEX
- Python深度學習
- Mastering AndEngine Game Development
- C#程序設(shè)計
- ASP.NET Core 2 Fundamentals
- C語言程序設(shè)計上機指導(dǎo)與習題解答(第2版)
- HTML5+CSS3 Web前端開發(fā)技術(shù)(第2版)
- Learning Concurrency in Kotlin
- Internet of Things with ESP8266
- Swift 4從零到精通iOS開發(fā)
- 輕松上手2D游戲開發(fā):Unity入門
- Creating Data Stories with Tableau Public
- Elasticsearch Essentials
- 深入淺出Python數(shù)據(jù)分析
- 信息學奧林匹克競賽初賽精講精練