classObj() {
return {
hideSidebar: !this.sidebar.opened,
openSidebar: this.sidebar.opened,
withoutAnimation: this.sidebar.withoutAnimation,
mobile: this.device === 'mobile'
};
},
```
.hideSidebar会transform: translate3d(-$sideBarWidth, 0, 0);
.main-container会
### 1.6.2 npm 安装
```
npm install js-cookie
npm install path-browserify
npm install vuex@3.6.2
npm install core-js@3.8.3
npm install fuse.js@3.4.4
npm install screenfull@4.2.0
npm install path-to-regexp@2.4.0
npm install sass@1.26.2 sass-loader@8.0.2
```
### 1.6.3. .eslintrc.js
根目录下面
```js
module.exports = {
root: true,
env: {
node: true
},
'extends': [
'plugin:vue/essential',
'eslint:recommended'
],
parserOptions: {
parser: '@babel/eslint-parser'
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
//在rules中添加自定义规则
//关闭组件命名规则
"vue/multi-word-component-names":"off",
//define no use
"no-unused-vars":"off",
"vue/no-unused-components": "off", // 当存在定义而未使用的组件时,关闭报错
"no-unused-vars":"off" // 当存在定义而未使用的变量时,关闭报错
},
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)'
],
env: {
jest: true
}
}
]
}
```
### 1.6.4 layout,styles引入
```js
特别注意
src/layout/components/Sidebar/index.vue下面的index
this.permission_routes这一块控制侧边路由
```
注意一下src/layout/index.vue里面,这个效果是根据一次项目的要求,pc端不要显示header和sidebar,只显示主体。然后移动端要是一样的东西
```js
mounted() {
// this.sidebar = {
// opened: true,
// withoutAnimation: false,
// },
// this.device = "desktop";
// this.fixedHeader = false;
// this.showSettings = true;
console.log(document.body.clientWidth,document.body.clientHeight,"宽和高")
console.log(document.body.clientWidth>800 && document.body.clientHeight>800,"is")
if(document.body.clientWidth>800 && document.body.clientHeight>800){
document.querySelector('.main-container').style.cssText = "margin-left:0px ";
document.querySelector('.sidebar-container').style.cssText = "display:none !important";
document.querySelector('.navbar').style.cssText = "display:none !important";
}
window.addEventListener('resize', this.$_resizeHandler)
},
```

### 1.6.4 mixin
这个是src/layout/mixin里面的,这里的目的是自适应
```
import store from '@/store'
const { body } = document
const WIDTH = 992 // refer to Bootstrap's responsive design
export default {
watch: {
$route(route) {
if (this.device === 'mobile' && this.sidebar.opened) {
store.dispatch('app/closeSideBar', { withoutAnimation: false })
}
}
},
beforeMount() {
window.addEventListener('resize', this.$_resizeHandler)
},
beforeDestroy() {
window.removeEventListener('resize', this.$_resizeHandler)
},
mounted() {
const isMobile = this.$_isMobile()
if (isMobile) {
store.dispatch('app/toggleDevice', 'mobile')
store.dispatch('app/closeSideBar', { withoutAnimation: true })
}
},
methods: {
// use $_ for mixins properties
// https://vuejs.org/v2/style-guide/index.html#Private-property-names-essential
$_isMobile() {
const rect = body.getBoundingClientRect()
return rect.width - 1 < WIDTH
},
$_resizeHandler() {
if (!document.hidden) {
const isMobile = this.$_isMobile()
store.dispatch('app/toggleDevice', isMobile ? 'mobile' : 'desktop')
if (isMobile) {
store.dispatch('app/closeSideBar', { withoutAnimation: true })
}
}
}
}
}
```
### 1.6.5 router中写入
```js
{
path: '/documentation',
component: () => import('@/layout'),
children: [
{
path: 'index',
component: () => import('@/views/home/home'),
name: 'Documentation',
meta: { title: 'Documentation', icon: 'documentation', affix: true }
}
]
},
```
访问documentation/index
### 1.6.6 main.js中写入
```js
import './styles/element-variables.scss'
import './icons'
import '@/styles/index.scss' // global css
```
## 1.6.7 vue.config.js中写入
```js
module.exports = {
devServer: {
proxy: {
"/api": {
target: "http://localhost:3000",
pathRewrite: { "^/api": "/" },
changeOrigin: true,
},
},
},
configureWebpack: {
resolve: {
fallback: { path: require.resolve('path-browserify') }
}
}
};
```