//计算属性
computed:{
// 如果按钮需要被禁用,则返回true,否则返回false
isBtnDisabled(){
if(this.selectedCateKeys.length!==3){
return true
}
return false
},
// 当前选中的三级分类的Id
cateId(){
if(this.selectedCateKeys.length===3){
return this.selectedCateKeys[2]
}
return null
}
}
<!-- 添加参数的对话框 -->
<el-dialog
:title="'添加'+titleText"
:visible.sync="addDialogVisible"
width="50%"
@close="addDialogClosed"
>
<el-form :model="addForm" :rules="addFormRules" ref="addFormRef" label-width="100px">
<el-form-item :label="titleText" prop="attr_name">
<el-input v-model="addForm.attr_name"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="addDialogVisible = false">取 消</el-button>
<el-button type="primary" @click="addDialogVisible = false">确 定</el-button>
</span>
</el-dialog>
// 控制添加对话框的显示与隐藏
addDialogVisible:false,
// 添加参数的表单数据对象
addForm:{
attr_name:''
},
// 添加表单的验证规则对象
addFormRules:{
attr_name:[
{ required: true, message: '请输入参数名称', trigger: 'blur' }
]
}
// 监听添加对话框的关闭事件
addDialogClosed(){
this.$refs.addFormRef.resetFields()
}
const routes = [
{ path: '/', redirect: '/login' },
{ path: '/login', component: Login },
{
path: '/home',
component: Home ,
redirect: '/welcome',
children:[
{ path: '/welcome', component: Welcome },
{ path: '/users', component: Users },
{ path: '/rights', component: Rights },
{ path: '/roles', component: Roles},
{ path: '/categories', component: Cate},
{ path: '/params', component: Params}
]
}
]
<!-- 右侧内容主体 -->
<el-main :style="{ 'height': mainH+'px' }">
<!-- 路由占位符 -->
<router-view></router-view>
</el-main>
1.1.import
import Vue from 'vue'
import Router from 'vue-router'
import index from '@/view/index'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'index',
component: index
}
]
})
1.2.require
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'index',
component: require(`@/view/index`).default
}
]
})
注意 require 后面有个 default
2.1.import
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'index',
component: () => import(`@/view/index`)
}
]
})
注意这是一个箭头函数
2.2.require
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'index',
component: resolve => (require([`@/view/index.vue`], resolve))
}
]
})
注意这是一个箭头函数
使用路由懒加载后,可以减小app.js文件的大小,从而缩短第一次打开vue项目的加载时间。