vue-cli中的小操作

1.想要 禁止用户在ios端缩放,那就在 根目录的index.html中 替换

<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">

2.关闭打包之后,js中生成 map的文件,只需在 config/index.js 中:

productionSourceMap: false,

3.配置跨域,在config/index.js中找到 proxyTable:{},改为

      '/api': {
        target: '需要跨域的网址',//如:http://tp.zlzjcyw.com/
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }

4.打包之后,发现dist中index.html路劲问题,在config/index.js 中,改变下assetsPublicPath

 // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: './',

5.配置路由的懒加载 router/index.js,

import login from '@/components/login'

将import改为

const login = r => require.ensure([], () => r(require('../components/login')), 'login')

6.修改单页的标题,2步
①.在router/index中,添加meta.title

{
      path: '/',
      name: 'ActicleDetail',
      component: ActicleDetail,
      meta: {
        title: '秀文采',
      }
    },

②.在main.js中,调用钩子函数,在路由加载之前读取标题

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  beforeCreate(){
    router.beforeEach((to, from, next) => {
      window.document.title = to.meta.title;
      next()
    })
  }
})

7.解决路由跳转时,让页面滚动到顶部,在router/index.js中,,添加scrollBehavior

export default new Router({
  scrollBehavior (to, from, savedPosition) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve({ x: 0, y: 0 })
      }, 0)
    })
  }

8.vue-cli打包后,css3兼容性没配置:package.json

  "browserslist": [
    "> 1%",
    "last 2 versions",
    "last 10 Chrome versions",
    "last 5 Firefox versions",
    "Safari >= 6",
    "ie > 8"
  ]
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,652评论 19 139
  • vue-cli搭建项目 确保安装了node与npm 再目标文件夹下打开终端 执行cnpm i vue-cli -g...
    Akiko_秋子阅读 8,495评论 1 22
  • 原文http://www.cnblogs.com/libin-1/p/6596810.html 版本号 vue-c...
    tengrl阅读 9,120评论 0 0
  • 今天女儿做数学新课堂,我发现认识方位这节课挺绕脑筋的,人和动物的题就以自身为中心,其他就以我们自己的眼光看,希望女...
    李烽熠妈阅读 861评论 0 0
  • 1, 会读书和不会读书,差别是很大的。 废话不多说,先上图。请对号入座。 2,“会读书”的秘密 想要知道怎样从“不...
    睡午觉的猫儿阅读 11,850评论 51 274