1
Is it possible I import the Axios no Mixins? I have a Rest API and am putting in a Mixin my code of GET, but I use Axios for that. When I try to import the Axios within the Mixins, he returns me:
Uncaught Syntaxerror: Unexpected token import at Mymixins.js:1
Mymixins.js
import axios from 'axios'
let getMixins = {
created() {
axios.get(`https://api.myjson.com/bins/17rqo1`)
.then(response => {
console.log( response )
})
.catch(e => {
// Errors
})
}
}
List.
<template>
<h1> Test Mixins <h1>
</template>
<script>
import axios from 'axios'
export default {
data: () => ({
dataItem: [],
errors: []
}),
mixins: [getListagem]
}
</script>
What am I doing wrong? I’m creating simple variable with . js because I wouldn’t want to use
`import myMixins from ./myMixins`
in my .see
There’s some way to do it?
Thank you!
So Sergio, so I know it works, because I would go through my webpack, there is no way I use a Mixins without using import getListagem from './Mymixins' in mine. Vue? Because in the future I will have my . Vue in folder inside folder, then it will be difficult to map by " .. /.. /.. /Mymixins " . Do you understand? Thank you!
– Jackson
Jackson, that’s right, you have to use folder paths
../../
. You can use... getListagem
in time ofmixins: [getListagem]
but to import that object into the file you have to useimport
orrequire
.– Sergio
Got it! Is there any way I can leave this global Mixin? Where I can access it from any . Go without using import?
– Jackson
@Jackson there’s a way to add mixins globally https://vuejs.org/v2/guide/mixins.html#Global-Mixin but it’s not 100% what you want, as it only adds methods that don’t run each
created
– Sergio
Hmm got it. I’m going to study it. Anyway, it helped me a lot! Thank you!! =)
– Jackson
@Jackson one thing that occurred to me is that you can have a store in each element and then call the store’s init method.
– Sergio