Teacher @ Vue School
Full Stack developer (10 years)
Husband and Father
Feature Request
Source Code
httpRequest?
cache?
notify?
authUser?
route?
globalState?
Your codebase can be
100% understood as a whole
Your codebase can be
100% understood as a whole
The scaffolding generated by
npm init vue@3
The scaffolding generated by
npm init vue@3
The scaffolding generated by
npm init vue@3
From the Vue.js Style Guide
app-popup.vue
https://vuejs.org/style-guide/
https://eslint.vuejs.org/
Use your IDE's quick find or file jumping feature to filter files
Get rid of the redundancy of keywords in filenames AND in the directory
import ClientForm from '@/components/ClientForm.vue'
Path | Route and Component Name | What it Does |
---|---|---|
/users | UsersIndex | List all the users |
/users/create | UsersCreate | Form to create the user |
/users/{id} | UsersShow | Display the users details |
/users/{id}/edit | UsersEdit | Form to edit the user |
const moduleA = {
state: () => ({ ... }),
mutations: { ... },
actions: { ... },
getters: { ... }
}
const moduleB = {
state: () => ({ ... }),
mutations: { ... },
actions: { ... }
}
const store = new Vuex.Store({
modules: {
a: moduleA,
b: moduleB
}
})
store.state.a // -> `moduleA`'s state
https://vueschool.io/articles/series/how-to-structure-a-large-scale-vue-js-application/
Some Miscellaneous Tips for Large Scale Apps
// Http.js
import axios from 'axios'
export default class Http{
async get(url){
const response = await axios.get(url);
return response.data;
}
// ...
}
// Http.js
export default class Http{
async get(url){
const response = await fetch(url);
return await response.json();
}
// ...
}
export default class Http{
async get(url){
try {
const response = await fetch(url);
return await response.json();
} catch (err) {
alert(err);
}
}
// ...
}
// Http.js
import Cache from './Cache.js'
export default class Http{
async get(url){
const cached = Cache.get(url)
if(cached) return cached
const response = await fetch(url);
return await response.json();
}
// ...
}
// AppIcon.vue
<template>
<FontAwesomeIcon v-if="type==='fa'" :icon="icon" />
<md_icon v-if="type=== 'md'">{{icon}}</md_icon>
</template>
<script>
export default{
props:{
type: { type: String, default: 'fa' },
icon: { type: String, required: true }
}
}
</script>
axios('https://someapi.com/posts/1')
post.find(1)
const app = createApp(App)
// Auto Register Base Components
const requireComponent = require.context('./components', true, /App[A-Z]\w+\.(vue|js)$/)
requireComponent.keys().forEach(function (fileName) {
let baseComponentConfig = requireComponent(fileName)
baseComponentConfig = baseComponentConfig.default || baseComponentConfig
const baseComponentName = baseComponentConfig.name || (
fileName
.replace(/^.+\//, '')
.replace(/\.\w+$/, '')
)
app.component(baseComponentName, baseComponentConfig)
})
app.mount('#app')
https://testing-library.com/docs/vue-testing-library/intro/
from
from
from