Last active
July 15, 2020 14:51
-
-
Save tnorthcutt/81f9b41b4d5bd1565d5258a1e00245b4 to your computer and use it in GitHub Desktop.
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
// in mixins/trailingSlash.js | |
export default (url) => { | |
return url.replace(/\/?$/, "/"); | |
}; | |
// in app.js | |
import trailingSlash from "./components/mixins/trailingSlash"; | |
Vue.mixin({ | |
methods: { | |
trailingSlash, | |
}, | |
}); | |
// in store/actions.js | |
import trailingSlash from "../components/mixins/trailingSlash"; | |
let apiUrlBase = trailingSlash(process.env.MIX_API_URL); |
Yeah, I like that better! Makes things tidier where it's used in Vuex. Nice idea 👏
Updated with suggestion from @shai126 and converted to arrow function.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Thinking out loud - would the other way round work too, so reuse isn't tied to an implementation detail of mixins?