Browse Source

update examples to use filters

dev
Evan You 9 years ago
parent
commit
bdb4b80595
  1. 5
      examples/commits/app.js
  2. 4
      examples/commits/index.html
  3. 4
      examples/grid/grid.js
  4. 2
      examples/grid/index.html
  5. 4
      examples/markdown/index.html
  6. 2
      examples/svg/index.html
  7. 3
      examples/svg/svg.js
  8. 2
      examples/todomvc/index.html
  9. 8
      examples/todomvc/js/app.js

5
examples/commits/app.js

@ -22,14 +22,17 @@ var demo = new Vue({
currentBranch: 'fetchData' currentBranch: 'fetchData'
}, },
methods: { filters: {
truncate: function (v) { truncate: function (v) {
var newline = v.indexOf('\n') var newline = v.indexOf('\n')
return newline > 0 ? v.slice(0, newline) : v return newline > 0 ? v.slice(0, newline) : v
}, },
formatDate: function (v) { formatDate: function (v) {
return v.replace(/T|Z/g, ' ') return v.replace(/T|Z/g, ' ')
}
}, },
methods: {
fetchData: function () { fetchData: function () {
var xhr = new XMLHttpRequest() var xhr = new XMLHttpRequest()
var self = this var self = this

4
examples/commits/index.html

@ -35,9 +35,9 @@
<ul> <ul>
<li v-for="record in commits"> <li v-for="record in commits">
<a :href="record.html_url" target="_blank" class="commit">{{ record.sha.slice(0, 7) }}</a> <a :href="record.html_url" target="_blank" class="commit">{{ record.sha.slice(0, 7) }}</a>
- <span class="message">{{truncate(record.commit.message)}}</span><br> - <span class="message">{{ record.commit.message | truncate }}</span><br>
by <span class="author"><a :href="record.author.html_url" target="_blank">{{ record.commit.author.name }}</a></span> by <span class="author"><a :href="record.author.html_url" target="_blank">{{ record.commit.author.name }}</a></span>
at <span class="date">{{formatDate(record.commit.author.date)}}</span> at <span class="date">{{ record.commit.author.date | formatDate }}</span>
</li> </li>
</ul> </ul>
</div> </div>

4
examples/grid/grid.js

@ -40,10 +40,12 @@ Vue.component('demo-grid', {
return data return data
} }
}, },
methods: { filters: {
capitalize: function (str) { capitalize: function (str) {
return str.charAt(0).toUpperCase() + str.slice(1) return str.charAt(0).toUpperCase() + str.slice(1)
}
}, },
methods: {
sortBy: function (key) { sortBy: function (key) {
this.sortKey = key this.sortKey = key
this.sortOrders[key] = this.sortOrders[key] * -1 this.sortOrders[key] = this.sortOrders[key] * -1

2
examples/grid/index.html

@ -16,7 +16,7 @@
<th v-for="key in columns" <th v-for="key in columns"
@click="sortBy(key)" @click="sortBy(key)"
:class="{ active: sortKey == key }"> :class="{ active: sortKey == key }">
{{ capitalize(key) }} {{ key | capitalize }}
<span class="arrow" :class="sortOrders[key] > 0 ? 'asc' : 'dsc'"> <span class="arrow" :class="sortOrders[key] > 0 ? 'asc' : 'dsc'">
</span> </span>
</th> </th>

4
examples/markdown/index.html

@ -12,7 +12,7 @@
<div id="editor"> <div id="editor">
<textarea :value="input" @input="update"></textarea> <textarea :value="input" @input="update"></textarea>
<div v-html="marked(input)"></div> <div v-html="compileMarkdown(input)"></div>
</div> </div>
<script> <script>
@ -22,7 +22,7 @@
input: '# hello' input: '# hello'
}, },
methods: { methods: {
marked: marked, compileMarkdown: marked,
update: _.debounce(function (e) { update: _.debounce(function (e) {
this.input = e.target.value this.input = e.target.value
}, 300) }, 300)

2
examples/svg/index.html

@ -44,7 +44,7 @@
<input name="newlabel" v-model="newLabel"> <input name="newlabel" v-model="newLabel">
<button @click="add">Add a Stat</button> <button @click="add">Add a Stat</button>
</form> </form>
<pre id="raw">{{json(stats)}}</pre> <pre id="raw">{{ stats }}</pre>
</div> </div>
<p style="font-size:12px">* input[type="range"] requires IE10 or above.</p> <p style="font-size:12px">* input[type="range"] requires IE10 or above.</p>

3
examples/svg/svg.js

@ -67,9 +67,6 @@ new Vue({
stats: stats stats: stats
}, },
methods: { methods: {
json: function (val) {
return JSON.stringify(val, null, 2)
},
add: function (e) { add: function (e) {
e.preventDefault() e.preventDefault()
if (!this.newLabel) return if (!this.newLabel) return

2
examples/todomvc/index.html

@ -38,7 +38,7 @@
</section> </section>
<footer class="footer" v-show="todos.length" v-cloak> <footer class="footer" v-show="todos.length" v-cloak>
<span class="todo-count"> <span class="todo-count">
<strong>{{ remaining }}</strong> {{ pluralize(remaining) }} left <strong>{{ remaining }}</strong> {{ remaining | pluralize }} left
</span> </span>
<ul class="filters"> <ul class="filters">
<li><a href="#/all" :class="{selected: visibility == 'all'}">All</a></li> <li><a href="#/all" :class="{selected: visibility == 'all'}">All</a></li>

8
examples/todomvc/js/app.js

@ -64,13 +64,15 @@
} }
}, },
// methods that implement data logic. filters: {
// note there's no DOM manipulation here at all.
methods: {
pluralize: function (n) { pluralize: function (n) {
return n === 1 ? 'item' : 'items' return n === 1 ? 'item' : 'items'
}
}, },
// methods that implement data logic.
// note there's no DOM manipulation here at all.
methods: {
addTodo: function () { addTodo: function () {
var value = this.newTodo && this.newTodo.trim(); var value = this.newTodo && this.newTodo.trim();
if (!value) { if (!value) {

Loading…
Cancel
Save