Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help me #1

Closed
qlp504847629 opened this issue Sep 22, 2020 · 5 comments
Closed

help me #1

qlp504847629 opened this issue Sep 22, 2020 · 5 comments

Comments

@qlp504847629
Copy link

nav 1 nav 2 nav 3 subnav 1 待办事项 wdgs option3 option4 subnav 2 option5 option6 option7 option8 subnav 3 option9 option10 option11 option12 Home List App Content
<script lang="ts"> import { reactive, toRefs} from 'vue' import { useRouter } from 'vue-router' export default { setup(){ const router = useRouter(); const state = reactive({ selectedKeys1: ['2'], selectedKeys2: ['1'], collapsed: false, openKeys: ['sub1'], }) const goUrl = (path: string) => { router.push(path); } return{ ...toRefs(state), goUrl } } }; </script> <style> </style>
@qlp504847629
Copy link
Author

<template>
  <a-layout id="components-layout-demo-top-side-2">
    <a-layout-header class="header">
      <div class="logo" />
      <a-menu
        theme="dark"
        mode="horizontal"
        v-model:selectedKeys="selectedKeys1"
        :style="{ lineHeight: '64px' }"
      >
        <a-menu-item key="1">
          nav 1
        </a-menu-item>
        <a-menu-item key="2">
          nav 2
        </a-menu-item>
        <a-menu-item key="3">
          nav 3
        </a-menu-item>
      </a-menu>
    </a-layout-header>
    <a-layout>
      <a-layout-sider width="200" style="background: #fff">
        <a-menu
          mode="inline"
          v-model:selectedKeys="selectedKeys2"
          v-model:openKeys="openKeys"
          :style="{ height: '100%', borderRight: 0 }"
        >
          <a-sub-menu key="sub1">
            <template v-slot:title>
              <span><user-outlined />subnav 1</span>
            </template>
            <a-menu-item key="1" @click="goUrl('/todo-list2')">待办事项</a-menu-item>
            <a-menu-item key="2"> <router-link to="/todo-list2">wdgs</router-link></a-menu-item>
            <a-menu-item key="3">option3</a-menu-item>
            <a-menu-item key="4">option4</a-menu-item>
          </a-sub-menu>
          <a-sub-menu key="sub2">
            <template v-slot:title>
              <span><laptop-outlined />subnav 2</span>
            </template>
            <a-menu-item key="5">option5</a-menu-item>
            <a-menu-item key="6">option6</a-menu-item>
            <a-menu-item key="7">option7</a-menu-item>
            <a-menu-item key="8">option8</a-menu-item>
          </a-sub-menu>
          <a-sub-menu key="sub3">
            <template v-slot:title>
              <span><notification-outlined />subnav 3</span>
            </template>
            <a-menu-item key="9">option9</a-menu-item>
            <a-menu-item key="10">option10</a-menu-item>
            <a-menu-item key="11">option11</a-menu-item>
            <a-menu-item key="12">option12</a-menu-item>
          </a-sub-menu>
        </a-menu>
      </a-layout-sider>
      <a-layout style="padding: 0 24px 24px">
        <a-breadcrumb style="margin: 16px 0">
          <a-breadcrumb-item>Home</a-breadcrumb-item>
          <a-breadcrumb-item>List</a-breadcrumb-item>
          <a-breadcrumb-item>App</a-breadcrumb-item>
        </a-breadcrumb>
        <a-layout-content
          :style="{ background: '#fff', padding: '24px', margin: 0, minHeight: '280px' }"
        >
          Content
        </a-layout-content>
      </a-layout>
    </a-layout>
  </a-layout>
</template>
<script lang="ts">
import { reactive, toRefs} from 'vue'
import { useRouter } from 'vue-router'
export default {
    setup(){
        const router = useRouter();
        const state = reactive({
            selectedKeys1: ['2'],
            selectedKeys2: ['1'],
            collapsed: false,
            openKeys: ['sub1'],
        })
        const goUrl = (path: string) => {
            router.push(path);
        }
        return{
            ...toRefs(state),
            goUrl
        }
    }
};
</script>

<style>

</style>

@qlp504847629
Copy link
Author

import {createRouter ,createWebHashHistory} from 'vue-router'

// 在 Vue-router新版本中,需要使用createRouter来创建路由
export default createRouter({
  // 指定路由的模式,此处使用的是hash模式
  history: createWebHashHistory(),
  // 路由地址
  routes: [
    {
      path: '/home',
      component: () => import('../views/home.vue')
    },
    {
      path: '/helloworld',
      component: () => import('../components/HelloWorld.vue')
    },
    {
      path: '/todolist',
      component: () => import('../views/todo-list.vue')
    },
    {
      path: '/todo-list2',
      component: () => import('../views/todo-list2.vue')
    }
  ]
})

@qlp504847629
Copy link
Author

@weizhanzhan
Copy link
Owner

https://github.com/qlp504847629/vue3-test.git

根据地址栏路由也进不去,你那边可以?

@weizhanzhan
Copy link
Owner

over 。构建工具vite,页面内使用的对象没在setup中定义并没有return ,导致路由跳转不到这个页面内

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants