How to rework an Angular1 App to a VueJs app
So I'll get right to it :
I'm trying to remake an existing app that used Angular 1 , instead using VueJS 2.
Being unfamiliar to Angular1 I find it challenging to decide on a few things :
1.What are factories(probably services), where do I place/write manage them?
2.Okay I know angular is big on controllers, but I cannot seem to understand if I were to use Vue , what's the alternative to the controller, and where to hold the code.
So, basically what I've gotten so far is to use VueX for state management and I have moved some services there, however - I can't figure out for example if a certain service @requires 'NameOfOtherService' , does it mean it imports it like in NodeJS const NameOfOtherService = require ('insert/path/here'); ?
Basically the app gets data from an API and php scripts, for example :
In the angular 1 version in my appsettings, which is using an AppConfig module I have a pathFromScript(script) => // etc.
My question is , how do I manage EVERYTHING that's going on within one app like that translated to Vue?
Thank you in advance I know it's entirely a shot in the dark here.
Yours truly ,
javascript angular vue.js module vuex
add a comment |
So I'll get right to it :
I'm trying to remake an existing app that used Angular 1 , instead using VueJS 2.
Being unfamiliar to Angular1 I find it challenging to decide on a few things :
1.What are factories(probably services), where do I place/write manage them?
2.Okay I know angular is big on controllers, but I cannot seem to understand if I were to use Vue , what's the alternative to the controller, and where to hold the code.
So, basically what I've gotten so far is to use VueX for state management and I have moved some services there, however - I can't figure out for example if a certain service @requires 'NameOfOtherService' , does it mean it imports it like in NodeJS const NameOfOtherService = require ('insert/path/here'); ?
Basically the app gets data from an API and php scripts, for example :
In the angular 1 version in my appsettings, which is using an AppConfig module I have a pathFromScript(script) => // etc.
My question is , how do I manage EVERYTHING that's going on within one app like that translated to Vue?
Thank you in advance I know it's entirely a shot in the dark here.
Yours truly ,
javascript angular vue.js module vuex
add a comment |
So I'll get right to it :
I'm trying to remake an existing app that used Angular 1 , instead using VueJS 2.
Being unfamiliar to Angular1 I find it challenging to decide on a few things :
1.What are factories(probably services), where do I place/write manage them?
2.Okay I know angular is big on controllers, but I cannot seem to understand if I were to use Vue , what's the alternative to the controller, and where to hold the code.
So, basically what I've gotten so far is to use VueX for state management and I have moved some services there, however - I can't figure out for example if a certain service @requires 'NameOfOtherService' , does it mean it imports it like in NodeJS const NameOfOtherService = require ('insert/path/here'); ?
Basically the app gets data from an API and php scripts, for example :
In the angular 1 version in my appsettings, which is using an AppConfig module I have a pathFromScript(script) => // etc.
My question is , how do I manage EVERYTHING that's going on within one app like that translated to Vue?
Thank you in advance I know it's entirely a shot in the dark here.
Yours truly ,
javascript angular vue.js module vuex
So I'll get right to it :
I'm trying to remake an existing app that used Angular 1 , instead using VueJS 2.
Being unfamiliar to Angular1 I find it challenging to decide on a few things :
1.What are factories(probably services), where do I place/write manage them?
2.Okay I know angular is big on controllers, but I cannot seem to understand if I were to use Vue , what's the alternative to the controller, and where to hold the code.
So, basically what I've gotten so far is to use VueX for state management and I have moved some services there, however - I can't figure out for example if a certain service @requires 'NameOfOtherService' , does it mean it imports it like in NodeJS const NameOfOtherService = require ('insert/path/here'); ?
Basically the app gets data from an API and php scripts, for example :
In the angular 1 version in my appsettings, which is using an AppConfig module I have a pathFromScript(script) => // etc.
My question is , how do I manage EVERYTHING that's going on within one app like that translated to Vue?
Thank you in advance I know it's entirely a shot in the dark here.
Yours truly ,
javascript angular vue.js module vuex
javascript angular vue.js module vuex
asked Nov 15 '18 at 7:33
Victor BonchevskiVictor Bonchevski
105
105
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
As for Vue.Js, your angular controllers are methods. If you need to get some data from an API, you can use a method to call a Vuex action and either return the value back to the method or add it to your state, so it's available everywhere. This will look like the example below.
I guess your factories / services are managing API calls. I would place that inside Vuex with axios to make API calls.
Methods is the same as controllers in Angular. You create methods on the specific page. If you need a method to be resused multiple places, you can use mixins. Mixins extends the specific page by importing it. You can read about it here: https://vuejs.org/v2/guide/mixins.html
page.vue
data
export default
import mapActions, mapGetters from 'vuex'
...
computed:
...mapGetters(
data: 'getData'
)
,
methods:
...mapActions(
getServerData: 'getDataFromServer'
)
,
created ()
this.getServerData()
store.js (vuex)
import axios from 'axios'
state:
data: null
,
getters:
getData: state =>
return state.data
,
mutations:
setDataFromServer: (state, payload) =>
state.data = payload
,
actions:
getDataFromServer: ( commit ) =>
return axios.get('https://website.com/api/data').then((response) =>
commit('setDataFromServer', response)
)
In this example the created is calling the vuex action to get the data from the server. When the server returns the value, it calls a mutation which sets the response in a state (data). The mapGetters which calls the getters in vuex, returns the data from state. It updates whenever the state changes.
Hope this makes sense
Yes it does make perfect sense, my entire trouble is cause I did make the VueX calls to the API, however I need to add an auth service - probably gonna do it in a separate module ofc , as the app is quite big. Regarding controllers I think I kinda get it now ? I mean It's the fact that Angular1 code looks so confusing to me idk why, but put it in REACT or whatever else it makes sense. Anyway Thank you so much for your response and I hope I can get things cleared off pretty soon , so I can get on with my life with the extra knowledge, you sir deserve a cookie :D
– Victor Bonchevski
Nov 15 '18 at 13:35
Thank you and i'm glad it made sense. If you don't use it, you could look in to this cli.vuejs.org/guide/creating-a-project.html#vue-create which is using Vue CLI 3. It creates a template so you'll be able to seperate it more into modules. If you need documentation on the Vue.Js lifecycle, here you go: vuejs.org/v2/guide/instance.html Just tell me if you have any other questions :) If my answer above was the "solution", please mark it as "Solution"
– Jonas Christensen
Nov 15 '18 at 13:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314435%2fhow-to-rework-an-angular1-app-to-a-vuejs-app%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As for Vue.Js, your angular controllers are methods. If you need to get some data from an API, you can use a method to call a Vuex action and either return the value back to the method or add it to your state, so it's available everywhere. This will look like the example below.
I guess your factories / services are managing API calls. I would place that inside Vuex with axios to make API calls.
Methods is the same as controllers in Angular. You create methods on the specific page. If you need a method to be resused multiple places, you can use mixins. Mixins extends the specific page by importing it. You can read about it here: https://vuejs.org/v2/guide/mixins.html
page.vue
data
export default
import mapActions, mapGetters from 'vuex'
...
computed:
...mapGetters(
data: 'getData'
)
,
methods:
...mapActions(
getServerData: 'getDataFromServer'
)
,
created ()
this.getServerData()
store.js (vuex)
import axios from 'axios'
state:
data: null
,
getters:
getData: state =>
return state.data
,
mutations:
setDataFromServer: (state, payload) =>
state.data = payload
,
actions:
getDataFromServer: ( commit ) =>
return axios.get('https://website.com/api/data').then((response) =>
commit('setDataFromServer', response)
)
In this example the created is calling the vuex action to get the data from the server. When the server returns the value, it calls a mutation which sets the response in a state (data). The mapGetters which calls the getters in vuex, returns the data from state. It updates whenever the state changes.
Hope this makes sense
Yes it does make perfect sense, my entire trouble is cause I did make the VueX calls to the API, however I need to add an auth service - probably gonna do it in a separate module ofc , as the app is quite big. Regarding controllers I think I kinda get it now ? I mean It's the fact that Angular1 code looks so confusing to me idk why, but put it in REACT or whatever else it makes sense. Anyway Thank you so much for your response and I hope I can get things cleared off pretty soon , so I can get on with my life with the extra knowledge, you sir deserve a cookie :D
– Victor Bonchevski
Nov 15 '18 at 13:35
Thank you and i'm glad it made sense. If you don't use it, you could look in to this cli.vuejs.org/guide/creating-a-project.html#vue-create which is using Vue CLI 3. It creates a template so you'll be able to seperate it more into modules. If you need documentation on the Vue.Js lifecycle, here you go: vuejs.org/v2/guide/instance.html Just tell me if you have any other questions :) If my answer above was the "solution", please mark it as "Solution"
– Jonas Christensen
Nov 15 '18 at 13:58
add a comment |
As for Vue.Js, your angular controllers are methods. If you need to get some data from an API, you can use a method to call a Vuex action and either return the value back to the method or add it to your state, so it's available everywhere. This will look like the example below.
I guess your factories / services are managing API calls. I would place that inside Vuex with axios to make API calls.
Methods is the same as controllers in Angular. You create methods on the specific page. If you need a method to be resused multiple places, you can use mixins. Mixins extends the specific page by importing it. You can read about it here: https://vuejs.org/v2/guide/mixins.html
page.vue
data
export default
import mapActions, mapGetters from 'vuex'
...
computed:
...mapGetters(
data: 'getData'
)
,
methods:
...mapActions(
getServerData: 'getDataFromServer'
)
,
created ()
this.getServerData()
store.js (vuex)
import axios from 'axios'
state:
data: null
,
getters:
getData: state =>
return state.data
,
mutations:
setDataFromServer: (state, payload) =>
state.data = payload
,
actions:
getDataFromServer: ( commit ) =>
return axios.get('https://website.com/api/data').then((response) =>
commit('setDataFromServer', response)
)
In this example the created is calling the vuex action to get the data from the server. When the server returns the value, it calls a mutation which sets the response in a state (data). The mapGetters which calls the getters in vuex, returns the data from state. It updates whenever the state changes.
Hope this makes sense
Yes it does make perfect sense, my entire trouble is cause I did make the VueX calls to the API, however I need to add an auth service - probably gonna do it in a separate module ofc , as the app is quite big. Regarding controllers I think I kinda get it now ? I mean It's the fact that Angular1 code looks so confusing to me idk why, but put it in REACT or whatever else it makes sense. Anyway Thank you so much for your response and I hope I can get things cleared off pretty soon , so I can get on with my life with the extra knowledge, you sir deserve a cookie :D
– Victor Bonchevski
Nov 15 '18 at 13:35
Thank you and i'm glad it made sense. If you don't use it, you could look in to this cli.vuejs.org/guide/creating-a-project.html#vue-create which is using Vue CLI 3. It creates a template so you'll be able to seperate it more into modules. If you need documentation on the Vue.Js lifecycle, here you go: vuejs.org/v2/guide/instance.html Just tell me if you have any other questions :) If my answer above was the "solution", please mark it as "Solution"
– Jonas Christensen
Nov 15 '18 at 13:58
add a comment |
As for Vue.Js, your angular controllers are methods. If you need to get some data from an API, you can use a method to call a Vuex action and either return the value back to the method or add it to your state, so it's available everywhere. This will look like the example below.
I guess your factories / services are managing API calls. I would place that inside Vuex with axios to make API calls.
Methods is the same as controllers in Angular. You create methods on the specific page. If you need a method to be resused multiple places, you can use mixins. Mixins extends the specific page by importing it. You can read about it here: https://vuejs.org/v2/guide/mixins.html
page.vue
data
export default
import mapActions, mapGetters from 'vuex'
...
computed:
...mapGetters(
data: 'getData'
)
,
methods:
...mapActions(
getServerData: 'getDataFromServer'
)
,
created ()
this.getServerData()
store.js (vuex)
import axios from 'axios'
state:
data: null
,
getters:
getData: state =>
return state.data
,
mutations:
setDataFromServer: (state, payload) =>
state.data = payload
,
actions:
getDataFromServer: ( commit ) =>
return axios.get('https://website.com/api/data').then((response) =>
commit('setDataFromServer', response)
)
In this example the created is calling the vuex action to get the data from the server. When the server returns the value, it calls a mutation which sets the response in a state (data). The mapGetters which calls the getters in vuex, returns the data from state. It updates whenever the state changes.
Hope this makes sense
As for Vue.Js, your angular controllers are methods. If you need to get some data from an API, you can use a method to call a Vuex action and either return the value back to the method or add it to your state, so it's available everywhere. This will look like the example below.
I guess your factories / services are managing API calls. I would place that inside Vuex with axios to make API calls.
Methods is the same as controllers in Angular. You create methods on the specific page. If you need a method to be resused multiple places, you can use mixins. Mixins extends the specific page by importing it. You can read about it here: https://vuejs.org/v2/guide/mixins.html
page.vue
data
export default
import mapActions, mapGetters from 'vuex'
...
computed:
...mapGetters(
data: 'getData'
)
,
methods:
...mapActions(
getServerData: 'getDataFromServer'
)
,
created ()
this.getServerData()
store.js (vuex)
import axios from 'axios'
state:
data: null
,
getters:
getData: state =>
return state.data
,
mutations:
setDataFromServer: (state, payload) =>
state.data = payload
,
actions:
getDataFromServer: ( commit ) =>
return axios.get('https://website.com/api/data').then((response) =>
commit('setDataFromServer', response)
)
In this example the created is calling the vuex action to get the data from the server. When the server returns the value, it calls a mutation which sets the response in a state (data). The mapGetters which calls the getters in vuex, returns the data from state. It updates whenever the state changes.
Hope this makes sense
edited Nov 16 '18 at 7:58
answered Nov 15 '18 at 8:45
Jonas ChristensenJonas Christensen
408
408
Yes it does make perfect sense, my entire trouble is cause I did make the VueX calls to the API, however I need to add an auth service - probably gonna do it in a separate module ofc , as the app is quite big. Regarding controllers I think I kinda get it now ? I mean It's the fact that Angular1 code looks so confusing to me idk why, but put it in REACT or whatever else it makes sense. Anyway Thank you so much for your response and I hope I can get things cleared off pretty soon , so I can get on with my life with the extra knowledge, you sir deserve a cookie :D
– Victor Bonchevski
Nov 15 '18 at 13:35
Thank you and i'm glad it made sense. If you don't use it, you could look in to this cli.vuejs.org/guide/creating-a-project.html#vue-create which is using Vue CLI 3. It creates a template so you'll be able to seperate it more into modules. If you need documentation on the Vue.Js lifecycle, here you go: vuejs.org/v2/guide/instance.html Just tell me if you have any other questions :) If my answer above was the "solution", please mark it as "Solution"
– Jonas Christensen
Nov 15 '18 at 13:58
add a comment |
Yes it does make perfect sense, my entire trouble is cause I did make the VueX calls to the API, however I need to add an auth service - probably gonna do it in a separate module ofc , as the app is quite big. Regarding controllers I think I kinda get it now ? I mean It's the fact that Angular1 code looks so confusing to me idk why, but put it in REACT or whatever else it makes sense. Anyway Thank you so much for your response and I hope I can get things cleared off pretty soon , so I can get on with my life with the extra knowledge, you sir deserve a cookie :D
– Victor Bonchevski
Nov 15 '18 at 13:35
Thank you and i'm glad it made sense. If you don't use it, you could look in to this cli.vuejs.org/guide/creating-a-project.html#vue-create which is using Vue CLI 3. It creates a template so you'll be able to seperate it more into modules. If you need documentation on the Vue.Js lifecycle, here you go: vuejs.org/v2/guide/instance.html Just tell me if you have any other questions :) If my answer above was the "solution", please mark it as "Solution"
– Jonas Christensen
Nov 15 '18 at 13:58
Yes it does make perfect sense, my entire trouble is cause I did make the VueX calls to the API, however I need to add an auth service - probably gonna do it in a separate module ofc , as the app is quite big. Regarding controllers I think I kinda get it now ? I mean It's the fact that Angular1 code looks so confusing to me idk why, but put it in REACT or whatever else it makes sense. Anyway Thank you so much for your response and I hope I can get things cleared off pretty soon , so I can get on with my life with the extra knowledge, you sir deserve a cookie :D
– Victor Bonchevski
Nov 15 '18 at 13:35
Yes it does make perfect sense, my entire trouble is cause I did make the VueX calls to the API, however I need to add an auth service - probably gonna do it in a separate module ofc , as the app is quite big. Regarding controllers I think I kinda get it now ? I mean It's the fact that Angular1 code looks so confusing to me idk why, but put it in REACT or whatever else it makes sense. Anyway Thank you so much for your response and I hope I can get things cleared off pretty soon , so I can get on with my life with the extra knowledge, you sir deserve a cookie :D
– Victor Bonchevski
Nov 15 '18 at 13:35
Thank you and i'm glad it made sense. If you don't use it, you could look in to this cli.vuejs.org/guide/creating-a-project.html#vue-create which is using Vue CLI 3. It creates a template so you'll be able to seperate it more into modules. If you need documentation on the Vue.Js lifecycle, here you go: vuejs.org/v2/guide/instance.html Just tell me if you have any other questions :) If my answer above was the "solution", please mark it as "Solution"
– Jonas Christensen
Nov 15 '18 at 13:58
Thank you and i'm glad it made sense. If you don't use it, you could look in to this cli.vuejs.org/guide/creating-a-project.html#vue-create which is using Vue CLI 3. It creates a template so you'll be able to seperate it more into modules. If you need documentation on the Vue.Js lifecycle, here you go: vuejs.org/v2/guide/instance.html Just tell me if you have any other questions :) If my answer above was the "solution", please mark it as "Solution"
– Jonas Christensen
Nov 15 '18 at 13:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314435%2fhow-to-rework-an-angular1-app-to-a-vuejs-app%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown