vue基础(二)

组件化高级

#### 插槽的基本使用
<div id="app">
	<cpn></cpn>
	<cpn></cpn>
	<cpn><i>1312321</i></cpn>
	<cpn></cpn>
</div>
<template id='cpn'>
	<div>
		<h2>1111</h2>
		<h3>22222</h3>
		<slot></slot>  //替换
	</div>
</template>
<script>

    const app = new Vue({
        el: "#app",
        data: {
            message: '你好',
        },
		components:{
			cpn:{
				template:'#cpn'
			}
		}
    })
	const cpn = {
		  template:'#cpn',
		  data(){
			  return{
			  }
		  } 
	}
</script>
 

具名插槽的使用

<div id="app">
	<cpn><span slot='center'>321321312312</span></cpn>
	<cpn><button slot='left'>返回</button></cpn>
</div>
<template id='cpn'>
	<div>
		<slot name='left'><span>左边</span></slot> 
		<slot name='center'><span>中间</span></slot>
		<slot name='r'><span>右边</span></slot> 
	</div>
</template>
<script>

    const app = new Vue({
        el: "#app",
        data: {
            message: '你好',
        },
		components:{
			cpn:{
				template:'#cpn'
			}
		}
    })
	const cpn = {
		  template:'#cpn',
	}
</script>
编译的作用域

插槽的案例

<div id="app">
	<cpn></cpn>
	<cpn>
		<template slot-scope='slot'>
			<span v-for='item in slot.data'>
				{{item}}-
			</span>
			
		</template>
	</cpn>
	<cpn>
		<template slot-scope='slot'>
			<span>
				{{slot.data.join('--')}}
			</span>
		</template>
	</cpn>
</div>
<template id='cpn'>
	<div>
		<slot :data='pLang'>
			<ul>
				<li v-for='item in pLang'>{{item}}</li>
			</ul>
		</slot>
	</div>
</template>
<script>
    const app = new Vue({
        el: "#app",
        data: {
            message: '你好',
			isShow:true
        },
		components:{
			cpn:{
				template:'#cpn',
				data(){
					return{
						pLang:['a0','b','v','d','r']
					}
				}
			}
		}
    })
</script>

模块化开发

导出  type='module'
方式1
export{
	flag,
	num
}
方式2
export var num=1000;
导出函数/export function null(a,b){
	return 1+1;
}
export class person{ //导出类
	run(){}
}
import {num,person} from "./xx.js" 
const address='山东济南'
export default address; //不命名

import add from "./xx.js"  //使用default 同一个模块里只能有一个,  add 不需要加{}
import * as abc from "./xx.js" 
alert(abc.num)

#路由懒加载

import Vue from 'vue'
import Router from 'vue-router'
// import HelloWorld from '@/components/HelloWorld'
// import Test from '@/components/Test'
const Test = () => import("@/components/Test")
Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'test',
      component:Test //或直接() => import("@/components/Test")
    }
  ]
})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值