首页 > 其他分享 >vue封装移动端日历选择和前后日期切换功能组件

vue封装移动端日历选择和前后日期切换功能组件

时间:2022-12-11 23:31:08浏览次数:43  
标签:vue 封装 nowDate1 日历 month let date false day


整体效果

vue封装移动端日历选择和前后日期切换功能组件_时间选择器组件

1.main.js文件引入element-ui(需要用install指令安装,这里不贴出来了)

vue封装移动端日历选择和前后日期切换功能组件_javascript_02


vue封装移动端日历选择和前后日期切换功能组件_前端_03

2.新建组件文件

vue封装移动端日历选择和前后日期切换功能组件_javascript_04

<template>
<div id="app">
<div class="choose-day-week-month-year-all">
<!-- 日历选择 -->
<div v-if="show.day">
<el-date-picker
v-model="gysForm.day"
type="date"
:format="date"
@change="changeDate(0)"
:clearable="false"
@focus="showMaskView(0)"
@blur="showMaskView(1)"
popper-class="popperClass"
/>
</div>
<div v-if="show.week">
<el-date-picker
v-model="gysForm.week"
type="week"
:format="startDate + '~' + endDate"
@change="changeDate(1)"
:clearable="false"
@focus="showMaskView(0)"
@blur="showMaskView(1)"
popper-class="popperClass"
/>
</div>
<div v-if="show.month">
<el-date-picker
v-model="gysForm.month"
type="month"
:format="startDate + '~' + endDate"
@change="changeDate(2)"
@focus="showMaskView(0)"
@blur="showMaskView(1)"
popper-class="popperClass"
:clearable="false"
/>
</div>
<!-- 日历前后切换 -->
<div class="choose-day-week-month-year">
<div
class="public-view"
@click="tapInfo1(index,time.length)"
:key="index"
v-for="(value, index) in time"
:class="{ active: rSelect1[index].isActive }"
>
{{ value.name }}
</div>
</div>
</div>

<div class="switch-view">
<div class="time-show-view" >

<div :class="show.day?'time-text-view':'time-text-view-week'">
{{getTime1()}}
<div class="left-image">
<img src="../../assets/left.png" mode="" @click="lastDate1">
</div>
<div class="right-image">
<img src="../../assets/right.jpg" mode="" v-if="flag1" @click="nextDate1">
</div>
</div>

</div>
</div>


</div>
</template>
<script>
import dayjs from "dayjs";
export default {
name: 'dateSelect',
props: {
msg: String,
show:Object,
time:Array
},
data(){
return{
gysForm: {
month: "",
week: "",
day:""
},
rSelect1:[
{"isActive":true},
{"isActive":false},
{"isActive":false},
],
flag1:false,//是否显示右箭头
showMask1: false, //日历蒙层控制
date:"",
startDate: "",
endDate: "",
hour: "--",
min: "--",
fullYear1: "",
endOfMonth: "",
month1: "",
nowDate1: "",
endDate1: "",
startDate1: "",
monthStart1: "", //月初
monthEnd1: "", //月末
monthShow1: "",
week1: "",
timeshow1: "",
start1: "",
end1: "",
currentFirstDate: "",

}
},
watch:{
show: {
deep: true,
handler: function (nVal) {
if (nVal) {
if (this.show.day) {
let result ={}
result.date=this.date
result.type='day'
this.$emit("date",result)

} else if (this.show.week) {
let result ={}
result.start=this.start1
result.end=this.end1
result.type='week'
this.$emit("date",result)
}else if (this.show.month) {
let result ={}
result.start=this.monthStart1
result.end=this.monthEnd1
result.type='month'
this.$emit("date",result)
}
}
},
},
date:{
deep: true,
handler: function (nVal) {
if (nVal) {
if (this.show.day) {
let result ={}
result.date=nVal
result.type='day'
this.$emit("date",result)
}
}
},
},
week1: {
deep: true,
handler: function (nVal) {
if (nVal) {
if (this.show.week) {
let result ={}
result.start=this.start1
result.end=this.end1
result.type='week'
this.$emit("date",result)
}
}
},
},
monthShow1: {
deep: true,
handler: function (nVal) {
if (nVal) {
if (this.show.month) {
let result ={}
result.start=this.monthStart1
result.end=this.monthEnd1
result.type='month'
this.$emit("date",result)
}
}
},
},
},
mounted(){
this.date = dayjs(new Date()).format('YYYY-MM-DD');
this.setDate1(new Date());
},
methods: {
showMaskView(item) {
if (item == 0) {
this.showMask1 = true;
document.body.style.overflow = "hidden";
} else {
this.showMask1 = false;
document.body.style.overflow = "auto";
}
},
changeDate(item){
if(item==0){
this.date=dayjs(this.gysForm.day).format('YYYY-MM-DD')
this.getFlag()
}else if(item==1){
this.currentFirstDate = new Date(dayjs(this.gysForm.week).endOf('week').format('YYYY-MM-DD'));
this.start1=dayjs(this.gysForm.week).startOf('week').format('YYYY-MM-DD')
this.end1=dayjs(this.gysForm.week).endOf('week').format('YYYY-MM-DD')
this.week1=dayjs(this.gysForm.week).startOf('week').format('YYYY/MM/DD')+'~'+dayjs(this.gysForm.week).endOf('week').format('YYYY/MM/DD')
//当前周的周末 用当前的周末日期与今天比,看是不是在本周
let date1 = this.formatDate(this.addDate(new Date(), 0));
let year = this.end1.split("-")[0];
let month = this.end1.split("-")[1];
let day = this.end1.split("-")[2];
//今天
let currentYear = date1.split("/")[0];
let currentMonth = date1.split("/")[1];
let currentDay = date1.split("/")[2];
//看当周是不是本周,如果不是,就显示右边的小箭头,否则隐藏
this.getWeekFlag1(
year,
month,
day,
currentYear,
currentMonth,
currentDay
);
}else{
this.startDate1=dayjs(this.gysForm.month).startOf('month').format('YYYY/MM/DD')
this.nowDate1 = new Date(dayjs(this.gysForm.month).startOf('month').format('YYYY-MM-DD'));
this.monthStart1=dayjs(this.gysForm.month).startOf('month').format('YYYY-MM-DD')
this.monthEnd1=dayjs(this.gysForm.month).endOf('month').format('YYYY-MM-DD')
this.monthShow1=dayjs(this.gysForm.month).startOf('month').format('YYYY/MM/DD')+'~'+dayjs(this.gysForm.month).endOf('month').format('YYYY/MM/DD')
this.getMonthFlag1();
}
// console.log(this.startDate+'-'+this.endDate)

},
getWeekFlag1(year, month, day, year1, month1, day1) {
if (year === year1 && month === month1) {
// console.log("同年同月");
if (day > new Date().getDate()) {
this.flag1 = false;
} else if (day === day1) {
this.flag1 = false;
} else {
this.flag1 = true;
}
} else if (year === year1) {
if (month > month1) {
this.flag1 = false;
} else {
this.flag1 = true;
}
} else {
if (year > year1) {
this.flag1 = false;
} else {
this.flag1 = true;
}
}
// console.log(this.flag1)
return this.flag1;
},
formatDate(date) {
let year = date.getFullYear() + "/";
let month = date.getMonth() + 1 + "/";
let day = date.getDate();
if (date.getMonth() + 1) {
month = "0" + month;
}
if (day < 10) {
day = "0" + day;
}
return year + month + day;
},
getTime1() {
if (this.show.day) {
return this.date;
}else if (this.show.week) {
return this.week1;
} else if (this.show.month) {
return this.monthShow1;
}
},
addDate(date, n) {
date.setDate(date.getDate() + n);
return date;
},
setDate1(date) {

let week;
if (date.getDay() - 1 === -1) {
week = date.getDay() + 6;
} else {
week = date.getDay() - 1;
}
date = this.addDate(date, week * -1);
// console.log(date,'date')
this.currentFirstDate = new Date(date);

let s = this.formatDate(this.addDate(date, -1)); //周日
let e = this.formatDate(this.addDate(date, 6)); //周6

this.week1 = s + "~" + e;
this.timeShow1 = s + "~" + e;
this.start1 = s.replace("/", "-").replace("/", "-");
this.end1 = e.replace("/", "-").replace("/", "-");
// console.log(this.start1)
//当前周的周末 用当前的周末日期与今天比,看是不是在本周
let date1 = this.formatDate(this.addDate(new Date(), 0));
let year = this.end1.split("-")[0];
let month = this.end1.split("-")[1];
let day = this.end1.split("-")[2];
//今天
let currentYear = date1.split("/")[0];
let currentMonth = date1.split("/")[1];
let currentDay = date1.split("/")[2];
//看当周是不是本周,如果不是,就显示右边的小箭头,否则隐藏
this.getWeekFlag1(
year,
month,
day,
currentYear,
currentMonth,
currentDay
);
},
getFullDate(targetDate) {
var D, y, m, d;
if (targetDate) {
D = new Date(targetDate);
y = D.getFullYear();
m = D.getMonth() + 1;
d = D.getDate();
} else {
y = fullYear;
m = month;
d = date;
}
m = m > 9 ? m : "0" + m;
d = d > 9 ? d : "0" + d;
return y + "/" + m + "/" + d;
},
getMonthFlag1() {
let month = parseInt(this.startDate1.split("/")[1]);
// console.log(new Date().getMonth()+1)
if (this.nowDate1.getFullYear() == new Date().getFullYear()) {
//同年
if (month == new Date().getMonth() + 1) {
//当前月份比这个月大
this.flag1 = false;
} else if (month < new Date().getMonth() + 1) {
//当前月份比这个月小
this.flag1 = true;
} else {
this.flag1 = false;
}
} else {
//不同年
if (this.nowDate1.getFullYear() > new Date().getFullYear()) {
//如果当前年份比今年大
this.flag1 = false;
} else {
//当前年份比今年小
this.flag1 = true;
}
}
},
getFlag(){
let year=parseInt(this.date.split("-")[0]) ;
let month=parseInt(this.date.split("-")[1]);
let day=parseInt(this.date.split("-")[2]);

if(year===new Date().getFullYear()&&month===(new Date().getMonth()+1)){
// console.log("同年同月");
if(day>new Date().getDate()){
// console.log("当前日期比今天大");
this.flag1=false;
}else if(day===new Date().getDate()){
// console.log("当前日期就是今天");
this.flag1=false;
}else{
// console.log("当前日期比今天小");
this.flag1=true;
}
}else if(year===new Date().getFullYear()){
if(month>(new Date().getMonth()+1)){
// console.log("当前日期比今天大");
this.flag1=false;
}else{
// console.log("当前日期比今天小");
this.flag1=true;
}
}else{
if(year>new Date().getFullYear()){
// console.log("当前日期比今天大");
this.flag1=false;
}else{
// console.log("当前日期比今天小");
this.flag1=true;
}
}
return this.flag1;
},
lastDate1(){
if(this.show.day){
this.date = dayjs(new Date(this.date).getTime()-86400000).format('YYYY-MM-DD');
this.getFlag();
}else if(this.show.week){
//周
// console.log(this.currentFirstDate)
this.setDate1(this.addDate(this.currentFirstDate,-7));


}else if(this.show.month){
//月

this.nowDate1.setMonth(this.nowDate1.getMonth()-1);
this.startDate1= this.nowDate1.getFullYear() + "/" + (this.nowDate1.getMonth()+1) + "/" + this.nowDate1.getDate()
this.endDate1 =this.getFullDate(new Date(this.nowDate1.getFullYear(), this.nowDate1.getMonth() + 1, 0))
let year=this.nowDate1.getFullYear()
let month = (this.nowDate1.getMonth()+1)
let day=this.nowDate1.getDate()
if(month<10){
month='0'+month
}
if(day<10){
day='0'+day
}
this.monthStart1=year+'-'+month+'-'+day
// this.monthStart1=this.nowDate1.getFullYear() + "-" + (this.nowDate1.getMonth()+1) + "-" + this.nowDate1.getDate()

this.monthEnd1=this.endDate1.replace('/','-').replace('/','-');

this.monthShow1=this.startDate1+"~"+this.endDate1;
this.getMonthFlag1()
// console.log(this.monthStart1,this.monthEnd1)

}

},
nextDate1() {
if(this.show.day){
this.date = dayjs(new Date(this.date).getTime()+86400000).format('YYYY-MM-DD');
this.getFlag();
}else if (this.show.week) {
//周
this.setDate1(this.addDate(this.currentFirstDate, 7));

} else if (this.show.month) {
this.nowDate1.setMonth(this.nowDate1.getMonth() + 1);
this.startDate1 =
this.nowDate1.getFullYear() +
"/" +
(this.nowDate1.getMonth() + 1) +
"/" +
this.nowDate1.getDate();
this.endDate1 = this.getFullDate(
new Date(this.nowDate1.getFullYear(), this.nowDate1.getMonth() + 1, 0)
);
this.monthShow1 = this.startDate1 + "~" + this.endDate1;
let year = this.nowDate1.getFullYear();
let month = this.nowDate1.getMonth() + 1;
let day = this.nowDate1.getDate();
if (month < 10) {
month = "0" + month;
}
if (day < 10) {
day = "0" + day;
}
this.monthStart1 = year + "-" + month + "-" + day;
// this.monthStart1=this.nowDate1.getFullYear() + "-" + (this.nowDate1.getMonth()+1) + "-" + this.nowDate1.getDate()
this.monthEnd1 = this.endDate1.replace("/", "-").replace("/", "-");
this.getMonthFlag1();
// console.log(this.monthStart1,this.monthEnd1)
}
},
tapInfo1(e,length) {
//切换
if(length==2){
switch(e){
// case 0:
// this.date = dayjs(new Date()).format('YYYY-MM-DD');
// this.rSelect1[0].isActive=true;
// this.rSelect1[1].isActive=false;
// this.rSelect1[2].isActive=false;

// break;
case 0:
//周
this.setDate1(new Date());
this.rSelect1[0].isActive=true;
this.rSelect1[1].isActive=false;
this.rSelect1[2].isActive=false;
this.show.week=true
this.show.month=false
this.show.day=false

break;
case 1:
//月
this.nowDate1 = new Date();
this.fullYear1 = this.nowDate1.getFullYear();
this.month1 = this.nowDate1.getMonth() + 1; // getMonth 方法返回 0-11,代表1-12月
this.endOfMonth1 = new Date(this.fullYear1, this.month1, 0).getDate(); // 获取本月最后一天
this.endDate1 = this.getFullDate(this.nowDate1.setDate(this.endOfMonth1));//当月最后一天
this.startDate1 = this.getFullDate(this.nowDate1.setDate(1));//当月第一天
// console.log(this.startDate1)
this.monthShow1=this.startDate1+"~"+this.endDate1;
let year=this.nowDate1.getFullYear()
let month = (this.nowDate1.getMonth()+1)
let day=this.nowDate1.getDate()
if(month<10){
month='0'+month
}
if(day<10){
day='0'+day
}
this.monthStart1=year+'-'+month+'-'+day
// this.monthStart1=this.nowDate1.getFullYear() + "-" + (this.nowDate1.getMonth()+1) + "-" + this.nowDate1.getDate()
this.monthEnd1=this.endDate1.replace('/','-').replace('/','-');
// console.log(this.monthStart1)
this.getMonthFlag1()
this.rSelect1[0].isActive=false;
this.rSelect1[1].isActive=true;
this.rSelect1[2].isActive=false;
this.show.week=false
this.show.month=true
this.show.day=false


}
}else if(length==3){
switch(e){
case 0:
this.leftLength="10% !important"
this.date = dayjs(new Date()).format('YYYY-MM-DD');
this.getFlag()
this.rSelect1[0].isActive=true;
this.rSelect1[1].isActive=false;
this.rSelect1[2].isActive=false;
this.show.week=false
this.show.month=false
this.show.day=true
break;
case 1:
//周
this.leftLength="15% !important"
this.setDate1(new Date());
this.rSelect1[0].isActive=false;
this.rSelect1[1].isActive=true;
this.rSelect1[2].isActive=false;
this.show.week=true
this.show.month=false
this.show.day=false
break;
case 2:
//月
this.leftLength="15% !important"
this.nowDate1 = new Date();
this.fullYear1 = this.nowDate1.getFullYear();
this.month1 = this.nowDate1.getMonth() + 1; // getMonth 方法返回 0-11,代表1-12月
this.endOfMonth1 = new Date(this.fullYear1, this.month1, 0).getDate(); // 获取本月最后一天
this.endDate1 = this.getFullDate(this.nowDate1.setDate(this.endOfMonth1));//当月最后一天
this.startDate1 = this.getFullDate(this.nowDate1.setDate(1));//当月第一天
// console.log(this.startDate1)
this.monthShow1=this.startDate1+"~"+this.endDate1;
let year=this.nowDate1.getFullYear()
let month = (this.nowDate1.getMonth()+1)
let day=this.nowDate1.getDate()
if(month<10){
month='0'+month
}
if(day<10){
day='0'+day
}
this.monthStart1=year+'-'+month+'-'+day
// this.monthStart1=this.nowDate1.getFullYear() + "-" + (this.nowDate1.getMonth()+1) + "-" + this.nowDate1.getDate()
this.monthEnd1=this.endDate1.replace('/','-').replace('/','-');
// console.log(this.monthStart1)
this.getMonthFlag1()
this.rSelect1[0].isActive=false;
this.rSelect1[1].isActive=false;
this.rSelect1[2].isActive=true;
this.show.week=false
this.show.month=true
this.show.day=false

}
}


},

}
}
</script>
<style>
.time-text-view-week{
position: relative;
width: 100%;
}
.time-text-view{
margin: 0 auto;
position: relative;
width: 75%;
}
.left-image{
position: absolute;
top: 0;
left: 7px;
}
.right-image{
position: absolute;
right: 7px;
top: 0;

}
.time-show-view{
width: 60%;
height: 22.5px;
position: relative;
margin: 0 auto;
line-height: 22.5px;
}
.switch-view img{
background: #FFFFFF;
width: 22.5px;
height: 22.5px;
z-index: 1000002;
}
.switch-view{
font-size: 14px;
background:#FFFFFF;
text-align: center;
width: 100%;
font-size: 13px;
font-weight: 300;
color: #333333;
opacity: 0.8;
margin-top: 12.5px;
z-index: 1000001;
}
.active{
color: #333333 !important;
width: 46px;
background:#FFBB24 !important;
background-color: #FFBB24;
border-radius: 5px;

}
.public-view{
width: 38px;
background:#F5F5F5;
background-color: #F5F5F5;
height: 24px;
display: inline-block;
text-align: center;
font-weight: 500;
color: #333333;
letter-spacing: 1px;
opacity: 1;
}
.choose-day-week-month-year{
margin: 30px auto;
width:114px;
line-height: 24px;
height: 24px;
border-radius: 5px;
overflow: hidden;
}
.el-popper .popper__arrow,
.el-popper .popper__arrow::after {
display: none;
}
.popperClass.el-date-picker {
background: rgba(252, 248, 239);
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
border-radius: 15px;
width: 90vw;
right: 0;
top: 50%;
transform: translate(0, 100px);
left: 50% !important;
margin-left: -45vw !important;
position: absolute !important;
z-index: 100000001 !important;
}
.popperClass.el-date-table td.end-date span,
.el-date-table td.start-date span {
background-color: #ffbb24;
color: black;
}
.popperClass.el-date-table td.start-date span,
.el-date-table td.end-date span {
color: black;
background-color: #ffbb24;
}
.el-date-table td.today span {
color: #606266;
font-weight: normal;
}
.el-date-table td.in-range div,
.el-date-table td.in-range div:hover,
.el-date-table.is-week-mode .el-date-table__row.current div,
.el-date-table.is-week-mode .el-date-table__row:hover div {
background-color: #fbeccb;
}
.el-icon-arrow-right:before {
color: #ffbb24;
}
.el-icon-d-arrow-right:before {
color: #ffbb24;
}
.el-icon-arrow-left:before {
color: #ffbb24;
}
.el-icon-d-arrow-left:before {
color: #ffbb24;
}
.el-icon-date:before {
color: #ffbb24;
width: 40vw !important;
height: 40vh !important;
border-radius: 50% !important;
font-size: 22px;
}

.el-input--prefix .el-input__inner {
display: none;
}
.el-month-table td.today .cell {
color: #666060;
font-weight: normal;
}
.el-month-table td.current:not(.disabled) .cell {
color: #666060;
background-color: #ffbb24;
}
/* .el-input__prefix,
.el-input__suffix {
top: 78px;
position: absolute;
bottom: 0 !important;
left: -10% !important;
color: #c0c4cc;
text-align: center;
z-index: 1000000;
} */
.el-input__prefix, .el-input__suffix{
top: 78px;
position: absolute;
bottom: 0 !important;
left: -10% !important;
color: #C0C4CC;
text-align: center;
z-index: 1000000;
}
</style>

3.使用方法

vue封装移动端日历选择和前后日期切换功能组件_当前日期_05


vue封装移动端日历选择和前后日期切换功能组件_vue.js_06


vue封装移动端日历选择和前后日期切换功能组件_javascript_07


具体的页面例子:

<template>
<div>
<!-- 日历组件 -->
<date-select @date='getDate' :show="show" :time="time"></date-select>
</div>
</template>
<script>

import DateSelect from '@/components/date-select/date-select.vue'
export default {
components: {DateSelect},
name: 'speedCharts',
props: {
msg: String
},
data() {
return {
show:{
'day':true,
'week':false,
'month':false,
},
time:[
{"name":"日"},
{"name":"周"},
{"name":"月"},
],
};
},
methods: {
getDate(data){
console.log(data)
if(data.type=='day'){
// data.date
}else if(data.type=='week'){
// data.start
// data.end
}else if(data.type=='month'){
// data.start
// data.end
}
}

}
}
</script>

<style >

</style>

4.效果

vue封装移动端日历选择和前后日期切换功能组件_时间选择器组件_08


vue封装移动端日历选择和前后日期切换功能组件_vue.js_09


vue封装移动端日历选择和前后日期切换功能组件_时间选择器组件_10


vue封装移动端日历选择和前后日期切换功能组件_vue.js_11


vue封装移动端日历选择和前后日期切换功能组件_javascript_12


vue封装移动端日历选择和前后日期切换功能组件_时间选择器组件_13


vue封装移动端日历选择和前后日期切换功能组件_时间选择器组件_14


vue封装移动端日历选择和前后日期切换功能组件_vue.js_15

5.只想要周和月的实现

vue封装移动端日历选择和前后日期切换功能组件_当前日期_16


代码修改的地方

vue封装移动端日历选择和前后日期切换功能组件_javascript_17


如果想要加上年的,可以自行阅读代码去加。


标签:vue,封装,nowDate1,日历,month,let,date,false,day
From: https://blog.51cto.com/wangjinchan/5928945

相关文章

  • vue组件间的通讯的10种方法
    https://blog.csdn.net/Serena_tz/article/details/124675515 1.props/$emitprops主要用于父组件传递数据给子组件,父==>子。Vue自定义事件父组件可以在使用子组件的地......
  • vue跨域问题
    例:浏览器在进行网络请求时 1.http :协议2.localhost:主机名3.8080:端口号 三者有一个不同,浏览器就会出现跨域问题 解决方法:proxyTable ......
  • vue无法获取flask设置的cookie
    最近在使用vue3开发基于flask后端的前后端分离项目时候,设置路由守卫时一直无法获取到登录后的cookie中session值但是在浏览器中却可以看到cookie先上代码router.befor......
  • Vue3忽略自定义模板组件提示
    为了在Vue应用程序中使用自定义元素库,必须修改应用程序以定义自定义元素和通知Vue编译器在编译过程中忽略哪些元素。根据同一页面,这可以通过修改Vue实例的配置来实......
  • 使用avue-form-design生成表单
    前言之前玩一些开源项目的时候有简单接触过可视化表单生成工具,也就是avue-form-design,当时重点都放在服务端了,前端的avue-form-design和avue并没有具体细看,这段时间刚好在搞......
  • vue项目day1
    构建项目vuecreatefinance-manager;cdfinance-manager;yarnserve安装依赖[email protected]......
  • DataGear 数据可视化看板整合前端框架Vue
    DataGear看板JS对象的loadUnsolvedCharts()函数,用于异步加载页面端动态生成的图表元素,利用它,可以很方便整合Angular、React、Vue等前端框架。本文以Vue为例,详细介绍如何......
  • vue基础知识
    我们呢,在第一篇笔记中也提到过vue的一个基础,今天的呢也就接着来 首先就是vue,我们需要知道他是怎么个运行,就是有以下这小三点:Node.js是我们的运行环境Vuecli......
  • vue3
    01-为什么学vue3目标:了解vue3现状,以及它的优点,展望它的未来Vue3现状:vue-next(opensnewwindow)2020年09月18日,正式发布vue3.0版本。但是由于刚发布周边生态不支持,......
  • Vue组件间传值(爷传孙,孙传爷)
    爷传孙首先说明:既然你学会了父传子,那么爷传孙自然不是难事,你可以先父传子,再子传孙,一步一步传,这里不再赘述。这里用到的方法是$attrs传参,比起上面的更简洁一些,首先我们还是......