I hate repeating things in code. For now I am importing vue files like this in my main.js.
import Default from '../../src/components/default.vue';
import Home from '../../src/components/home.vue';
import hakkinda from '../../src/components/hakkinda.vue';
import projeler from '../../src/components/projeler.vue';
import servisler from '../../src/components/servisler.vue';
import yetenekler from '../../src/components/yetenekler.vue';
import yetenek from '../../src/components/yetenek.vue';
import referanslar from '../../src/components/referanslar.vue';
import iletisim from '../../src/components/iletisim.vue';
Is there a way to do same thing with less lines? Could be great if I can assign variable name from filename. Can PHP help about it? But then how to compile main.js? I did not figured out.
VUE file extension is mainly associated with single file components used by Vue, an open-source, frontend JavaScript framework for building user interfaces. Such VUE single-file components are modules containing source code (typically for a single UI component) which can be exported or reused in a Vue application.
There are two ways to import a JavaScript library to the Vue Component. The first is to import a local JavaScript library. Here, you can import the JavaScript library by using the 'import' keyword inside the script tag of your Vue file. import * as mykey from '../assets/js/mykey.
A VUE (. vue) file is an editable ASCII file. You create a VUE file using the VUE file renderer. A VUE file contains a sequence of frames to render.
I use this script in a file named "index.js" to "export default all exported default in every file in the current folder" sort of thing:
const files = require.context('.', false, /\.js$/)
const modules = {}
files.keys().forEach((key) => {
if (key === './index.js') return
modules[ key.replace(/(\.\/|\.js)/g, '') ] = files(key).default
})
export default modules
Then you can import the whole directory by importing it's name, just like this:
import folder from '../path/to/folder'
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With