File tree Expand file tree Collapse file tree 12 files changed +49
-18
lines changed Expand file tree Collapse file tree 12 files changed +49
-18
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import { recentHistory } from './vuex/getters'
18
18
export default {
19
19
vuex: {
20
20
actions,
21
- state : {
21
+ getters : {
22
22
count : state => state .count ,
23
23
recentHistory
24
24
}
Original file line number Diff line number Diff line change 5
5
< title > vuex counter example</ title >
6
6
</ head >
7
7
< body >
8
- < counter > </ counter >
8
+ < div id =" app " > </ div >
9
9
< script src ="build.js "> </ script >
10
10
</ body >
11
11
</ html >
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import store from './vuex/store'
3
3
import Counter from './Counter.vue'
4
4
5
5
new Vue ( {
6
- el : 'body ' ,
6
+ el : '#app ' ,
7
7
store,
8
- components : { Counter }
8
+ render : h => h ( Counter )
9
9
} )
Original file line number Diff line number Diff line change
1
+ const digitsRE = / ( \d { 3 } ) (? = \d ) / g
2
+
3
+ export function currency ( value , currency , decimals ) {
4
+ value = parseFloat ( value )
5
+ if ( ! isFinite ( value ) || ( ! value && value !== 0 ) ) return ''
6
+ currency = currency != null ? currency : '$'
7
+ decimals = decimals != null ? decimals : 2
8
+ var stringified = Math . abs ( value ) . toFixed ( decimals )
9
+ var _int = decimals
10
+ ? stringified . slice ( 0 , - 1 - decimals )
11
+ : stringified
12
+ var i = _int . length % 3
13
+ var head = i > 0
14
+ ? ( _int . slice ( 0 , i ) + ( _int . length > 3 ? ',' : '' ) )
15
+ : ''
16
+ var _float = decimals
17
+ ? stringified . slice ( - 1 - decimals )
18
+ : ''
19
+ var sign = value < 0 ? '-' : ''
20
+ return sign + currency + head +
21
+ _int . slice ( i ) . replace ( digitsRE , '$1,' ) +
22
+ _float
23
+ }
Original file line number Diff line number Diff line change 5
5
< title > vuex shopping cart example</ title >
6
6
</ head >
7
7
< body >
8
- < app > </ app >
8
+ < div id =" app " > </ div >
9
9
< script src ="build.js "> </ script >
10
10
</ body >
11
11
</ html >
Original file line number Diff line number Diff line change @@ -2,9 +2,12 @@ import 'babel-polyfill'
2
2
import Vue from 'vue'
3
3
import App from './components/App.vue'
4
4
import store from './vuex/store'
5
+ import { currency } from './currency'
6
+
7
+ Vue . filter ( 'currency' , currency )
5
8
6
9
new Vue ( {
7
- el : 'body ' ,
10
+ el : '#app ' ,
8
11
store,
9
- components : { App }
12
+ render : h => h ( App )
10
13
} )
Original file line number Diff line number Diff line change 25
25
<footer class =" footer" v-show =" todos.length" >
26
26
<span class =" todo-count" >
27
27
<strong >{{ remaining }}</strong >
28
- {{ remaining | pluralize 'item' }} left
28
+ {{ remaining | pluralize( 'item') }} left
29
29
</span >
30
30
<ul class =" filters" >
31
- <li v-for =" (key, val ) in filters" >
32
- <a href =" #/{{$ key}} "
31
+ <li v-for =" (val, key ) in filters" >
32
+ <a : href =" '#/' + key"
33
33
:class =" { selected: visibility === key }"
34
34
@click =" visibility = key" >
35
35
{{ key | capitalize }}
@@ -96,6 +96,10 @@ export default {
96
96
}
97
97
e .target .value = ' '
98
98
}
99
+ },
100
+ filters: {
101
+ pluralize : (n , w ) => n === 1 ? w : (w + ' s' ),
102
+ capitalize : s => s .charAt (0 ).toUpperCase () + s .slice (1 )
99
103
}
100
104
}
101
105
</script >
Original file line number Diff line number Diff line change @@ -40,10 +40,10 @@ export default {
40
40
}
41
41
},
42
42
directives: {
43
- focus (value ) {
43
+ focus (el , { value }, { context } ) {
44
44
if (value) {
45
- this . vm .$nextTick (() => {
46
- this . el .focus ()
45
+ context .$nextTick (() => {
46
+ el .focus ()
47
47
})
48
48
}
49
49
}
Original file line number Diff line number Diff line change 5
5
< title > vuex todomvc example</ title >
6
6
</ head >
7
7
< body >
8
- < app > </ app >
8
+ < div id =" app " > </ div >
9
9
< script src ="build.js "> </ script >
10
10
</ body >
11
11
</ html >
Original file line number Diff line number Diff line change @@ -4,6 +4,6 @@ import App from './components/App.vue'
4
4
5
5
new Vue ( {
6
6
store, // inject store to all children
7
- el : 'body ' ,
8
- components : { App }
7
+ el : '#app ' ,
8
+ render : h => h ( App )
9
9
} )
You can’t perform that action at this time.
0 commit comments