Skip to content

Instantly share code, notes, and snippets.

@jsdecena
Last active September 19, 2018 12:12
Show Gist options
  • Save jsdecena/e1c54ecb515a9aa6db6ee2c868a44c6e to your computer and use it in GitHub Desktop.
Save jsdecena/e1c54ecb515a9aa6db6ee2c868a44c6e to your computer and use it in GitHub Desktop.
External class in Vue
// 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