在components中间了一个导航栏,在components中detail可以打印出结果,在page页面中打印显示undefind,这是什么问题?
components代码:
wxml代码:
<view class="segment-group">
<view class="segment-header">
<block wx:for="{{items}}" wx:key="item">
<view class="segment-item active" wx:if="{{currentIndex === index}}" bindtap="onItemTapEvent" data-index="{{index}}">{{item}}</view>
<view class="segment-item" wx:else bindtap="onItemTapEvent" data-index="{{index}}">{{item}}</view>
</block>
</view>
<view class="segment-body">
<block wx:for="{{items}}" wx:key="item">
<slot name="{{index}}" wx:if="{{currentIndex === index}}"></slot>
</block>
</view>
</view>
js代码:
Component({
options:{
multipleSlots:true
},
/**
* 组件的属性列表
*/
properties: {
items:{
type:Array,
value:[]
},
defaultIndex:{
type:Number,
value:0
}
},
/**
* 组件的初始数据
*/
data: {
currentIndex:0,
tabcurrent: 'tab1',
scrollTop: 0,
},
lifetimes:{
attached:function(){
var that=this;
this.setData({
currentIndex:that.properties.defaultIndex
})
}
},
/**
* 组件的方法列表
*/
methods: {
onItemTapEvent:function(event){
var index=event.target.dataset.index;
// console.log(index);
this.setData({
currentIndex:index
})
var detail={"index":index};
var options={};
this.triggerEvent("itemchanged",detail.options);
},
}
})
page代码:
wwxml代码:
<segment items="{{items}}" defaultIndex="0"
binditemchanged="onSegmentItemChanged" >
<view slot="0" class="segment-page car"></view>
<view slot="1" class="segment-page people"></view>
<view slot="2" class="segment-page truck"></view>
<view slot="3" class="segment-page goods"></view>
</segment>
js代码:
Page({
/**
* 页面的初始数据
*/
data: {
items:['我要找车','我要找人','我找货车','我要找货'],
},
onSegmentItemChanged:function(event){
console.log(event);
},
没问题啊,detail.options 你是没赋值的