cdn引入实现vue-router的嵌套路由

项目背景

目前的项目是基于若依框架的前后不分离的项目开发的后台管理项目,在此基础上进行迭代开发。

尝试:目前按钮权限是采用<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">的方式进行权限控制的,直接用vue-cli构建一个项目部署的话,按钮的权限无法根据后台设置的角色控制,这个不行;

看了一下若依的文档,然后新的页面的是在vue、vue-router、iview、Thymeleaf,在静态HTML中写vue代码。

实现嵌套路由的代码

index.html

<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head th:replace="init :: header('待办项目')"></head>

<body>
  <!-- 默认先不显示HTML中的内容,是由于一开始经后端渲染的时候,这个vue还没加载好,会显示没处理的HTML -->
  <div id="app" style="opacity: 0">
    <router-view></router-view>
  </div>
  <!-- 利用thymeleaf引入公共组件,加载vue、vue-router的写在公共的页面中了 -->
  <div th:replace="init :: expand"></div>
  <div th:replace="init :: base"></div>
  <div th:replace="init :: iview"></div>
  <div th:replace="init :: footer"></div>
  <!--    项目基础信息详情组件-->
  <div th:replace="city/projectInfo/components/baseProjectInfo :: baseProjectInfoComponents"></div>
  <div th:replace="city/projectInfo/components/baseProjectInfo :: uploadFilesComponents"></div>
  <!--    项目上传相关组件-->
  <div th:replace="city/projectInfo/components/newItemForm :: newProjectItemFormComponents"></div>
  <!--    历史详情组件-->
  <div th:replace="city/projectInfo/components/projectHistory :: projectHistoryComponents"></div>
  <!--    流程处理的路由页面-->
  <div th:replace="city/projectInfo/components/dealProject :: dealProjectHistoryComponents"></div>
  <div th:replace="city/projectInfo/components/dealProject :: dealProjectInfoComponents"></div>

  <script>
    let routes = [
      { path: '/', name: 'index', },
      { path: '/newProject', name: 'newProject', component: NewProjectItemFormComponent, },
      {
        path: '/projectHistory',
        name: 'projectHistory',
        // 组件的变量是利用thymeleaf定义在其他文件中
        component: ProjectHistoryComponent,
        children: [
          { path: '/projectHistory/bdGroup', name: 'projectHistoryBdGroup', component: BDGroupDealProjectInfo },
          { path: '/projectHistory/index/:projectCode', name: 'projectHistoryIndex', component: DealProjectHistory, }
        ]
      },
    ];
    let router = new VueRouter({
      routes: routes
    })
    let vm = new Vue({
      router,
      el: '#app',
      data() {
        return {}
      },
      created() {
        $('#app').css('opacity', '1');
        this.loading = true
      },
    })
  </script>
</body>

</html>

init.html

公共的组件引用

<div th:fragment="base">
    <script th:src="@{/js/vue.min.js}"></script>
    <script th:src="@{/js/vue-router.js}"></script>
    <script th:src="@{/js/axios.min.js}"></script>
    <script th:src="@{/ajax/libs/layui/layui.js}"></script>
</div>
<div th:fragment="iview">
    <link th:href="@{/css/iview.css}" rel="stylesheet" />
    <script th:src="@{/js/iview.min.js}"></script>
</div>

projectHistory.html

<div th:fragment="projectHistoryComponents">
  <style>
  </style>
  <script type="text/x-template" id="projectHistory">
      <tempalte>
          <div class="project-history-wrapper">
            <router-view></router-view>
          </div>
      </tempalte>
  </script>
  <script>
    let ProjectHistoryComponent = Vue.component("ProjectHistory", {
      data() {
        return {
        }
      },
      template: "#projectHistory",
    });
  </script>
</div>

组件属性props定义

以前工程化项目都没有这个问题,直接在HTML写会转成全小写才能注册props,或者按官方的写法

Prop 的大小写 (camelCase vs kebab-case)

HTML 中的 attribute 名是大小写不敏感的,所以浏览器会把所有大写字符解释为小写字符。这意味着当你使用 DOM 中的模板时,camelCase (驼峰命名法) 的 prop 名需要使用其等价的 kebab-case (短横线分隔命名) 命名:

Vue.component('blog-post', {
  // 在 JavaScript 中是 camelCase 的
  props: ['postTitle'],
  template: '<h3>{{ postTitle }}</h3>'
})
<!-- 在 HTML 中是 kebab-case 的 -->
<blog-post post-title="hello!"></blog-post>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值