1
In a Vue.Js component I use this Script template as in the example. On a getter, I inserted a Return of what is received
const GetSegmento = () => (param) => {
return (() => {
return param
})(param)
}
"He will be evolved as I can do what I seek here"
In my component I try to receive the Object or Value that my getter returns in data
> segmento
where I intend to use once for something else, what I’d like to know is, how do I get the executed return, or just the result in the case when using the Getter GetSegmento
in part Data
?
In case I put the this.GetSegmento(this.$route)
within the Console.log
is working perfectly, but would like to use within the Data
if that is possible, of course, I do not know if it is possible or how to do.
export default {
data: () => ({
segmento: s => this.GetSegmento(this.$route)
}),
onIdle () {
console.log(this.segmento)
}
}
That’s what comes back when I use the form above
ƒ segmento(s) {
return _this.GetSegmento(_this.$route);
}
The real goal is also to know if it is possible to use it in a Constant in the following example.
const segmento = s => this.GetSegmento(this.$route)
export default {
computed: {
...mapGetters('Modules', [ 'Segmento1', 'Segmento2' ])
},
onIdle () {
console.log(this[segmento])
}
}
Explanation with Files
The file I’m referring to is a file of the kind .vue
, one template
in the following format
<template>
<div>{{ segmento }}</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
data: () => ({
segmento: ''
}),
computed: {
...mapGetters('GetUm', [ 'SegmentoUm' ]),
...mapGetters('GetDois', [ 'SegmentoDois' ])
},
mounted () {
console.log(this.SegmentoUm(this.$route)) // funciona muito bem
console.log(this.SegmentoDois(this.$route)) // funciona muito bem
},
methods: {
getSegmento () {
this.segmento = this.SegmentoUm(this.$route.meta.segmento) // funciona também
this.segmento = this.SegmentoDois(this.$route.meta.segmento) // funciona também
}
}
}
The only thing I want is to know if it is possible and how to carry out the execution and return of the result of SegmentoUm
and or SegmentoDois
within the data: segmento
or within a const
outside the export default
as in the example below:
<template>
<div>{{ segmento }}</div>
</template>
<script>
import { mapGetters } from 'vuex'
const segmento = this.SegmentoUm // ou aqui
export default {
data: () => ({
segmento: this.SegmentoUm // ou aqui
}),
computed: {
...mapGetters('GetUm', [ 'SegmentoUm' ]),
...mapGetters('GetDois', [ 'SegmentoDois' ])
},
mounted () {
console.log(this.SegmentoUm(this.segmento)) // então vejo aqui
},
methods: {
getSegmento () {
this.segmento = this.SegmentoUm(segmento) // ou aqui
}
}
}
Just an aside (I’m still reading the question): the parameter
})(param)
IIFE is unnecessary, since you’re not using it as an argument in function.– Sergio
You can show the store file for that
Modules
? The question is interesting but not quite clear yet...– Sergio
@Sergio but in question I did not manipulate the
Store
, I don’t need to take information fromStore
, only need, if possible, run a getter ondata
orconst
– Roberto Monteiro
@Sergio this
})(param)
will still be assembled, and it will be used for adispatch
further on– Roberto Monteiro
I don’t understand what you mean by "getter on date," why don’t you use a
computed
for that? If we realize(s) the problem the answer does not take long :)– Sergio
@Sergio is that my goal is not to use the getter in
created
or in themounted
and in thecomputed
is the getter, but I want to execute him on adata
or in aconst
– Roberto Monteiro
Hi, I’m sorry about my lack of time, I read it now and I still don’t understand what you want to do :) You can create an example here or in jsFiddle, simple, so you can understand better...?
– Sergio
Use this jsFiddle if possible: https://jsfiddle.net/chrisvfritz/50wL7mdz/
– Sergio
Opa meu amigo @Sergio , rapaz, this is almost what I want to do https://codepen.io/flourigh/pen/vYBpgrx the problem is that I use mapState, mapGetters, mapMuttations, IE, in the example of the link, seems to work as I wish but could not do being mapGetters
– Roberto Monteiro
Is this what you’re looking for? https://codepen.io/sergiocrisostomo/pen/WNedXdJ?editors=1010 Whenever you use the
mapGetters
you have to passstore: store,
in the object that will be a Vue instance.– Sergio
@Sergio then, in this format, really works, the format I sent also works, the problem is in namespace format, IE, I’m using separate modules for each thing, IE, in this fomato that sent I was able to make work even in the example I sent, already in this format here https://codepen.io/flourigh/pen/eYOyLBm - https://codepen.io/flourigh/pen/eYOyLBm.html - https://codepen.io/flourigh/pen/eYOyLBm.babel I could not get it to work
– Roberto Monteiro
Then you must use
SelectPagamento
in the template where you haveexpress
and no express or date– Sergio
@Sergio there in the mustashe is just an example, I want to use as in this format
[express]name
or in fact[segmento]name
just as I use if const is fixed with a string, not a Function, I just want to call a Function in const and receive the Function result because I’m getting Function as in the question– Roberto Monteiro
You can use
SelectPagamento.name
... orSelectPagamento ? SelectPagamento.name : ''
. Create an example in codepen just like the one you want but it doesn’t work– Sergio
@Sergio beauty, I will try this and I warn you or create the model you mentioned
– Roberto Monteiro