File tree Expand file tree Collapse file tree 5 files changed +31
-4
lines changed Expand file tree Collapse file tree 5 files changed +31
-4
lines changed <
10000
/div>
Original file line number Diff line number Diff line change
1
+ exports . install = function ( ) {
2
+ F . route ( '/api/hello_msg' , hello_json )
3
+ }
4
+
5
+ function hello_json ( ) {
6
+ this . json ( { msg : 'Hello from API' } )
7
+ }
Original file line number Diff line number Diff line change 1
1
module . exports = {
2
+ build :{
3
+ vendor : [ 'axios' ]
4
+ } ,
2
5
srcDir : 'nuxt/'
3
6
}
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div >
3
3
<h3 >Hello from Total.js and Nuxt.js</h3 >
4
- <div class =" react-container" >
4
+ <div class =" container" >
5
+ <p >Value from server</p >
6
+ <p >{{serverMsg}}</p >
7
+ </div >
8
+ <div class =" container" >
5
9
<p >These values are React</p >
6
10
<input :value =" msg" @input =" (e)=>{setMsg(e.target.value)}" />
7
11
<p >{{msg}}</p >
12
16
</template >
13
17
<script >
14
18
import {mapState , mapMutations } from ' vuex'
19
+ import axios from ' axios'
15
20
export default {
16
21
computed: {
17
- ... mapState ([' msg' , ' counter' ])
22
+ ... mapState ([' msg' , ' counter' , ' serverMsg ' ])
18
23
},
19
24
methods: {
20
25
... mapMutations ([' setMsg' , ' increase' , ' decrease' ])
26
+ },
27
+ fetch : function ({store, req}) {
28
+ return axios .get (req .uri .protocol + ' //' + req .uri .host + ' /api/hello_msg' ).then (function (res ) {
29
+ store .commit (' setServerMsg' , res .data .msg )
30
+ }).catch (function (e ) {
31
+ console .log (e)
32
+ })
21
33
}
22
34
}
23
35
</script >
24
36
<style scoped>
25
- .react- container {
37
+ .container {
26
38
padding : 0 20px 20px 20px ;
27
39
margin : 10px ;
28
40
border-color : darkgray ;
Original file line number Diff line number Diff line change @@ -4,7 +4,8 @@ const store = function () {
4
4
return new Vuex . Store ( {
5
5
state : {
6
6
msg : '' ,
7
- counter : 0
7
+ counter : 0 ,
8
+ serverMsg : ''
8
9
} ,
9
10
mutations : {
10
11
setMsg : function ( state , msg ) {
@@ -15,6 +16,9 @@ const store = function () {
15
16
} ,
16
17
decrease : function ( state ) {
17
18
state . counter -= 1
19
+ } ,
20
+ setServerMsg : function ( state , msg ) {
21
+ state . serverMsg = msg
18
22
}
19
23
}
20
24
} )
Original file line number Diff line number Diff line change 14
14
"author" : " ckpiggy" ,
15
15
"license" : " MIT" ,
16
16
"dependencies" : {
17
+ "axios" : " ^0.16.2" ,
17
18
"nuxt" : " ^1.0.0-alpha.4" ,
18
19
"total.js" : " ^2.6.3-3"
19
20
}
You can’t perform that action at this time.
0 commit comments