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 ...
随机推荐
- Java函数式接口
函数式接口定义且只定义了一个抽象方法.函数式接口的抽象方法的签名称为函数描述符.Java 8的java.util.function包中引入了几个新的函数式接口. 1.Predicate java.ut ...
- vue打包后css背景图片地址找不到
背景图片变成了这样:static/css/static/imgs/xxx.jpg 解决方法,修改build/utils,添加 publicPath: '../../' 就行 对比了下,com ...
- latex公式居中环境
一般能够用到的环境是 \begin{equation} \begin{aligned} ... \end{aligned} \end{equation} 然而,这种环境用&只能够保证左对齐或者 ...
- ASE19 团队项目 模型组 scrum report集合
scrum report 链接 scrum1 report scrum2 report scrum3 report scrum4 report scrum5 report scrum6 report ...
- ActiveMQ基础简介
1. 什么是ActiveMQ ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现 ...
- mac-svn代码管理
一.mac下svn管理代码 //1.打开命令行工具,cd 到要拉取的代码放置位置 //2.从svn上拉取项目代码:svn checkout svn项目地址 (--username=XXX --pass ...
- springboot整合mybatis-plus基于纯注解实现一对一(一对多)查询
因为目前所用mybatis-plus版本为3.1.1,感觉是个半成品,所有在实体类上的注解只能支持单表,没有一对一和一对多关系映射,且该功能还在开发中,相信mybatis-plus开发团队在不久的将来 ...
- 提升Scrapy框架爬取数据效率的五种方式
1.增加并发线程开启数量 settings配置文件中,修改CONCURRENT_REQUESTS = 100,默认为32,可适当增加: 2.降低日志级别 运行scrapy时会产生大量日志占用CPU,为 ...
- inputrc命令
问题:搭建ubuntu系统后,输入命令的第一个字符+上页按键,发现不能找到历史命令,找了好久才发现是因为/etc/inputrc没有对键盘映射的上页键和下页键进行设置. 解决方法: 修改文件/etc/ ...
- 排序算法之快速排序QuickSort
挖坑填数-快速排序 1. left = L,right = R;将基准数挖出形成第一个坑s[left]; 2. right --; 由后向前找比它小的数,找到后挖出此数填前一个坑s[left]中. 3 ...