- 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'
});
推薦閱讀
- HornetQ Messaging Developer’s Guide
- Mastering Ext JS(Second Edition)
- SoapUI Cookbook
- Oracle Database In-Memory(架構與實踐)
- 數據庫系統原理及MySQL應用教程
- Asynchronous Android Programming(Second Edition)
- Java Web開發詳解
- Android移動開發案例教程:基于Android Studio開發環境
- 搞定J2EE:Struts+Spring+Hibernate整合詳解與典型案例
- Kubernetes進階實戰
- Clojure Polymorphism
- Hack與HHVM權威指南
- 青少年Python趣味編程
- Python面向對象編程(第4版)
- Flutter之旅