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 ...
随机推荐
- RSA加密-解密以及解决超长内容加密失败解决
加解密(没有使用到证书):https://blog.csdn.net/qy20115549/article/details/83105736 生成证书网站:https://blog.csdn.net/ ...
- nginx代理 tomcat获得真实用户IP
nginx代理 tomcat获得真实用户IP 2017年04月08日 21:34:17 cf 阅读数 1825更多 分类专栏: nginx html/js/ajax 版权声明:本文为博主原创文章, ...
- 【已解决】Field injection is not recommended和Could not autowired. No beans of 'xxx' type found.
目录 问题 解决办法 备注 问题 在项目中,我们使用Spring的@Autowired注解去引入其他类时有时候阿里的编码规约插件就会提示:"Field injection is not re ...
- java lesson14Homework
/** * 1. 本程序找出字符串数组 String[] arr = {“welcome”, “china”, “hi”, “congratulation”, “great”} 中的长度最大的元素,并 ...
- C#进阶之WebAPI(一)
最近出去面试,被问到关于WebAPI的知识,因为项目中没有单独写过WebAPI,使用的时候是和mvc结合在一起使用的,所以,在我的印象中WebAPI和mvc是差不多的,这种答案当然不能让人满意了,于是 ...
- linux mint 安装微信
安装nodejs 到nodejs官网下载node js压缩包,然后解压到自己设置的目录.我的解压路径是 /home/congwiny/Develop/SoftWare/node-v6.10.3-lin ...
- HTML的学习2(代码)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 采购订单保存生成PO号后增强点。
EXIT_SAPMM06E_013 这个增强可用于生成的PO后,调用外部接口把变更或生成的PO信息下发出去. 这里面的参数 I_EKKO 是新的抬头 I_EKKO_OLD 是更改前的抬头 XEKPO ...
- 利用fadeTo改变元素的不透明度代码
有很多的图片网站中有这样的一种效果:鼠标划过某个元素的时候,与他同级的其他元素的透明度会降低,突出显示这个元素,比如聚美优品的网站就多少用到了这个特效,效果图如下: 不多说,干货代码如下: html部 ...
- 使用脚本启动fabric时出错
Error: got unexpected status: BAD_REQUEST -- error authorizing update: error validating ReadSet: rea ...