Last active
September 19, 2018 12:12
-
-
Save jsdecena/e1c54ecb515a9aa6db6ee2c868a44c6e to your computer and use it in GitHub Desktop.
External class in Vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Question: How can I extract the "DataTransformer" class and reference it back here? | |
// Solved!!! | |
<script> | |
// extract this in <root>/src/helpers/helper.js (or anywhere you want it) | |
export class DataTransformer { | |
static transform(data) { | |
const transformedData = {}; | |
.... | |
return transformedData | |
} | |
} | |
// and import it like this | |
import { DataTransformer } from '@/helpers/helper.js'; | |
export default { | |
name: 'hello', | |
data() { | |
return { | |
world: {} | |
} | |
}, | |
methods: { | |
getUsers() { | |
.... | |
.then( | |
(res) => { | |
this.world = DataTransformer.transform(response.data) | |
} | |
); | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment