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 ...
随机推荐
- pat l2-14 列车调度 dilworth+nlog(n)最长上升子序列
关于dilworth定理 这里引用一个大神的(http://blog.csdn.net/xuzengqiang/article/details/7266034) 偏序的概念: 设A是一个非空集,P是A ...
- 初识python之了解其背景和安装
1.Python的发展 Python语言诞生于1990年,由Guido van Rossum设计并领导开发.1989年12月,Guido考虑启动一个开发项目以打发圣诞节前后的时间,所以决定为当时正在构 ...
- Spring中常用的设计模式之:代理模式
看了tom老师讲的深入分析spring源码,讲的挺好,做个小总结 代理模式的定义: 为其他对象提供一种代理以控制对这个对象的访问.在某些情况下,一个对象不适合或者不能直接引用另一个对象,而代理对象可以 ...
- 在django中部署vue项目,不单独抽离dist文件
1,在django项目下(app所在目录),新建vue项目,使用脚手架构建vue项目,vue create (项目名) 2,构建好以后,配置django: (1),配置settings: · 修改te ...
- MySQL之常用查询
1) 查询字符集 show variables like 'character%'; 2)查看版本 select version(); 3) 共享表空间的数据文件存储路径 show variables ...
- 1.Linux文件及目录结构
Linux 文件结构 在Linux中 ,一切皆文件 目录结构
- vue+elementui搭建后台管理界面
1 会话存储 使用html5的 sessionStorage 对象临时保存会话 // 保存会话 sessionStorage.setItem('user', username) // 删除会话 ses ...
- css改变背景透明度
透明往往能产生不错的网页视觉效果,先奉上兼容主流浏览器的CSS透明代码:.transparent{filter:alpha(opacity=90); -moz-opacity:0.9; -khtml- ...
- SQL语句 case ... when
select 字段A, 字段B, CASE WHEN t.operate = 1 then 'aa'WHEN t.operate = 2 then 'bb'WHEN t.operate = 3 the ...
- ClassLoader心得
我们都知道,jvm执行的代码,都是通过jvm加载系统加入的.加载系统的第一步是通过ClassLoader加载class二进制信息,jvm规范中并没有规定class的来源类型,这就给 ...