Rumah  >  Artikel  >  hujung hadapan web  >  详细解读在VUE中有关ie9兼容性

详细解读在VUE中有关ie9兼容性

亚连
亚连asal
2018-06-12 14:46:441824semak imbas

本篇文章主要介绍了如何去除vue项目中的#及其ie9兼容性,现在分享给大家,也给大家做个参考。

一、如何去除vue项目中访问地址的#

vue2中在路由配置中添加mode(vue-cli创建的项目在src/router/index.js)

export default new Router({
 mode: 'history',
 routes: [
  {
   path: '/',
   name: 'menu',
   component: menu,
   children: [
    {
     path: 'organization',
     component: organization,
     children: [
      {
       path: '',
       redirect: 'organizationSub'
      },
      {
       path: 'organizationSub',
       component: organizationSub
      }
     ]
    },
    {
     path: 'user',
     component: user
    },
    {
     path: 'role',
     component: role
    }
   ]
  }
 ]
})

二、vue路由原理

2.1  hash模式:vue-router默认的路由模式。

vue开发的单页面应用,html只有一个,切换时url的变化通过url的hash模式模拟完整的url。

2.2  history模式:vue2中配置 mode: 'history'。

利用history.pushState API完成url的跳转

HTML5 History 模式官网介绍:https://router.vuejs.org/zh-cn/essentials/history-mode.html

三、注意事项

不过这种模式要玩好,还需要后台配置支持。因为我们的应用是个单页客户端应用,如果后台没有正确的配置,当用户在浏览器直接访问 http://oursite.com/user/id 就会返回 404,这就不好看了。

所以呢,你要在服务端增加一个覆盖所有情况的候选资源:如果 URL 匹配不到任何静态资源,则应该返回同一个 index.html 页面,这个页面就是你 app 依赖的页面。

vue-router官网中有介绍,也有后台配置样例:https://router.vuejs.org/zh-cn/essentials/history-mode.html

四、兼容性

经过测试,mode: 'history'在ie9下不生效,若vue项目需要兼容ie9,且后台对访问地址有严格校验,不建议使用此种模式。若是内容有错误或遗漏,欢迎大家批评指正~

上面是我整理给大家的,希望今后会对大家有帮助。

相关文章:

微信小程序使用Promise如何实现回调?

在JS中命令模式概念与用法(详细教程)

使用selenium抓取淘宝数据信息

Atas ialah kandungan terperinci 详细解读在VUE中有关ie9兼容性. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn