Blogger Information
Blog 62
fans 3
comment 1
visits 29552
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
VUE组件和路由
kiraseo_wwwkiraercom
Original
350 people have browsed it

VUE组件

代码

  1. <template>
  2. <div>组件</div>
  3. <!-- 自定义的标签 -->
  4. <hello></hello>
  5. </template>
  6. <script>
  7. import hello from './components/HelloWorld.vue';
  8. export default{
  9. components :{
  10. //后面的值,是引入的文件
  11. //前面的key ,是给这个文件下标的名称
  12. hello: hello,
  13. },
  14. data(){
  15. return{
  16. }
  17. },
  18. //methods 配置项json格式
  19. methods : {
  20. //配置项里的方法
  21. }
  22. }
  23. </script>
  24. <style>
  25. </style>

效果

自定义组件基本写法

一个vue文件引入多个自定义组件

组件中引入组件

组件传值

组件固定传值与动态传值的对比

组件向页面传值

VUE路由

代码 app.vue

  1. <template>
  2. <div id="nav">
  3. <router-link to="/">首页</router-link> |
  4. <router-link to="/lists">列表</router-link> |
  5. <router-link to="/course">课程列表</router-link> |
  6. <router-link to="/User">个人中心</router-link>
  7. </div>
  8. <router-view />
  9. </template>
  10. <style>
  11. </style>

index.js

  1. import { createRouter, createWebHistory } from 'vue-router'
  2. //引入页面方式
  3. import index from '../views/Index.vue'
  4. import Lists from '../views/Lists.vue'
  5. import Course from '../views/Course.vue'
  6. import User from '../views/User.vue'
  7. const routes = [
  8. {
  9. path: '/',
  10. name: 'home',
  11. component: index
  12. },
  13. {
  14. path: '/Lists',
  15. name: 'Lists',
  16. component: Lists
  17. },
  18. {
  19. path: '/Course',
  20. name: 'Course',
  21. component: Course
  22. },
  23. {
  24. path: '/User',
  25. name: 'User',
  26. component: User
  27. },
  28. ]
  29. const router = createRouter({
  30. history: createWebHistory(process.env.BASE_URL),
  31. routes
  32. })
  33. export default router

效果

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post