vue子路由设置、全局组件、局部组件的原生写法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.bootcss.com/vue-router/3.0.6/vue-router.js"></script>
</head>
<style>
.view{
width:300px;
height:300px;
background:purple;
}
.childView{
width:100px;
height:100px;
background:green;
}
.aa{
width:100px;
height:70px;
background:yellow;
}
.bb{
width:100%;
height:50px;
background:cyan;
}
</style>
<body>
<div id="app">
<com1></com1>
<com2></com2>
<div class="view">
<router-link to="/com2">com2</router-link>
<router-view></router-view>
</div>
</div> <template id="childcom">
<div>
我是子路由
</div>
</template>
<template id="another">
<div>
<router-link to="/com2/com4">我是另一个路由</router-link>
<div class="bb">
<router-view></router-view>
</div> </div>
</template>
<script>
var objarr=[
{id:0,text:"二"},
{id:1,text:"三"},
{id:2,text:"四"},
{id:3,text:"五"},
{id:4,text:"六"},
{id:5,text:"七"}
] var component1={//局部组件
data(){
return{
aaa:objarr
}
},
template:`<div>
局部组件
<div v-for="(item,index) in aaa">
<span>{{ item.id }}</span>
<span>{{ item.text }}</span>
</div>
</div>`
} //声明个全局组件
Vue.component("com2",{
template:`<div>
全局组件
<div v-for="(item,index) in bbb" :key="index">
<span>{{ item.id }}</span>
<span>{{ item.text }}</span>
</div>
</div>`,
data(){
return{
bbb:objarr
}
},
}) // router
const routes = [
{ path: '/', component: component1 },
{ path: '/com2',
component:{template:'#another'},
children:[
{
path:'com4',
component:{template:"#childcom"}
}
]
}
]
const router = new VueRouter({
routes // (缩写) 相当于 routes: routes
}) new Vue({
el:"#app",
components:{
com1:component1
},
router
})
</script>
</body>
</html>
vue子路由设置、全局组件、局部组件的原生写法的更多相关文章
- vue教程3-03 vue组件,定义全局、局部组件,配合模板,动态组件
vue教程3-03 vue组件,定义全局.局部组件,配合模板,动态组件 一.定义一个组件 定义一个组件: 1. 全局组件 var Aaa=Vue.extend({ template:'<h3&g ...
- vue自定义组件(vue.use(),install)+全局组件+局部组件
相信大家都用过element-ui.mintui.iview等诸如此类的组件库,具体用法请参考:https://www.cnblogs.com/wangtong111/p/11522520.html ...
- Vue(2)- v-model、局部组件和全局组件、父子组件传值、平行组件传值
一.表单输入绑定(v-model 指令) 可以用 v-model 指令在表单 <input>.<textarea> 及 <select> 元素上创建双向数据绑定. ...
- vue-learning:13 - js - vue作用域概念:全局和局部
目录 全局作用域:Vue对象 全局api 局部作用域: 实例对象vm 实例api 组件component 组件配置选项 在引入Vue文件时,就相当于拥有了一个全局Vue对象. 在var vm = ne ...
- vue项目中设置全局引入scss,使每个组件都可以使用变量
在Vue项目中使用scss,如果写了一套完整的有变量的scss文件.那么就需要全局引入,这样在每个组件中使用. 可以在mian.js全局引入,下面是使用方法. 1: 安装node-sass.sass- ...
- vue之element-ui设置全局弹出框
这样的需求,在主要功能完成后,需要进行交互效果的完善,需要给请求api的时候添加一个加载中的一个弹出框.但是每个页面每个页面过的话,会很费时间和精力,这里我们可以采用element-ui中的服务式弹出 ...
- Vue其他指令-组件-全局-局部-组件的交互父传子
v-once指令 once:一旦,当...时候 <!DOCTYPE html> <html lang="zh"> <head> <meta ...
- Vue 根组件,局部,全局组件 | 组件间通信,案例组件化
一 组件 <div id="app"> <h1>{{ msg }}</h1> </div> <script src=" ...
- Vue 组件&组件之间的通信 之全局组件与局部组件
在上篇博客中介绍了组件,在注册组件的简写中就用到了全局组件 //注册组件的简写方式 Vue.component('my-componenta',{ template:'<h2>hello ...
随机推荐
- 怎样在 Vue 中使用 v-model 处理表单?
主要是通过 v-model 对表单元素做数据的 双向绑定. 用法其实也很简单, 只是因为表单元素有不同类型, 处理方式有些许不同, 这点需要注意. 1. 如果是 输入框 , 可以直接使用 v-mode ...
- O028、nova-compute 部署 instance 详解
参考https://www.cnblogs.com/CloudMan6/p/5451276.html 本节讨论 nova-compute ,并详细分析 instance 部署的全过程. nov ...
- 记录FTPClient超时处理的相关问题(转)
https://www.cnblogs.com/dasusu/p/10006899.html 记录 FTPClient 超时处理的相关问题 apache 有个开源库:commons-net,这个开 ...
- vue中的常用三元
点击事件的三元 <el-button type="primary" @click="edit == 'mod' ? sureModify() : submit()& ...
- 根据返回数据, 迭代数组, 构造HTML结构
首先需要引入jQuery哈! 1. 要求用下面的格式制作目录, 结构如下: <ul> <li>xxxx</li> <li>xxxx</li> ...
- https://bbs.ichunqiu.com/thread-48915-1-1.html
使用BurpSuite进行双文件上传拿Webshell 首先进入网站后台:(后台界面应该是良精CMS) <ignore_js_op> 在 添加产品 这一栏有个上传文件: <ignor ...
- C# 使用Quartz.Net
//首先在Nuget上下载 Quartz包 但是由于我睿智Nuget 怎么也没法用 于是找到了这个 解决方法: 1.点击右侧的设置按钮, 2.弹出窗中左侧树形结构选择“程序包源”,再点击右上方的添加按 ...
- 单点登录系统SSO实现
前些天被问到单点登录了,而据我当时做的这个模块两年了,现在重新温习并记录下,方便以后快速回忆起来 一.什么是单点登录系统 SSO全称Single Sign On.SSO是用户只需要登录一次就可以访问所 ...
- 3、Rsync备份服务实战
1.Rsync基本概述 rsync是一款开源的备份工具,可以在不同主机之间进行同步,可实现全量备份与增量备份,因此非常适合用于架构集中式备份或异地备份等应用. rsync官方地址:传送门http:// ...
- IoT 设备通信安全讨论
IoT 设备通信安全讨论 作者:360CERT 0x00 序言 IoT 设备日益增多的今天,以及智能家居这一话题愈发火热,智能家居市场正在飞速的壮大和发展,无数 IoT 设备正在从影片中不断的走向用户 ...