export default {
name: '名称',components: { // 组件挂载a},
created(){} 数据获取
beforeMount() {},
data: () => ({}),响应式数据
computed: {} 计算属性集合
methods: {} 方法集合
... 销毁页面不要的资源
}
async beforeMount(){
开始加载
this.loading = true
try {
const data = await getUserInfo()
} catch (error) {
console.log(error)
} finally {
停止加载
false
}
}
proxy: {
"/api": {
target: 'http://.......'true,1)"> 是否改变域名
ws: socket
pathRewrite: {
路径重写
"/api": '' 对拼接内容进行重写
}
},....
}
-- config
--- dev.js
--- build.js
--- public.js
vue.config.js
# 代码 vue.config.js
const devConfig = require('./config/dev')
const buildConfig = require('./config/build')
module.exports = process.env.NODE_ENV === 'development' ? devConfig : buildConfig
计算属性
computed: {
filterList: function () {
return this.showData.filter( (data) {
返回需要显示的数据
return data.isShow
})
}
DOM
<ul>
<li v-for="item in filterList" :key="item.id">
{{ item.name }}
</li>
</ul>
tableFactory(action) {
switch (action) {
case 'update':
...
break;
case 'create';
case 'delete';
:
...默认获取列表
;
}
}
props: {
test: {
type: String,1)">default: ''
},test2: {
type: [Number,String],1)">default: 1
GanMessage.vue组件
export {
name: 'GanMessage'
.....
}
引入后使用
components: {
[GanMessage.name]: GanMessage
}
模板中使用
<template>
<gan-message/>
</template>
vue.prototype.$logs = window.console.log;
使用
<template>
{{$logs('1111')}}
</template>
async beforeMount(){
const data = await getUserInfo();
}
watch: {
obj: {
handler(newName,oldName) {
console.log('obj.a changed');
},immediate: true'obj.a': {
handler(newName,oldName) {
console.log('obj.a changed');
},1)"> deep: true
}
}
<!-- Child -->
<template>
<input type="text" @input="$emit('custom-event','hello')" />
</template>
<!-- Parent -->
<template>
<Child @custom-event="handleCustomevent" />
</template>
<script>
export {
methods: {
handleCustomevent (value) {
console.log(value) hello
}
}
}
</script>