omi-mp - fix triggerEvent && directory compatible with mac os and window
This commit is contained in:
parent
195ea0a051
commit
3941960681
|
@ -11,7 +11,7 @@ gulp.task('components', ['copy'], () => {
|
|||
.pipe(
|
||||
tap(file => {
|
||||
let dir = path.dirname(file.path)
|
||||
let arr = dir.split('\\')
|
||||
let arr = dir.split(/\\|\//)
|
||||
let name = arr[arr.length-1]
|
||||
let wxml = fs.readFileSync(dir + '/' + name + '.wxml', 'utf8')
|
||||
let json = require(dir + '/' + name + '.json')
|
||||
|
@ -50,7 +50,14 @@ class Element extends WeElement {
|
|||
|
||||
afterUpdate() {}
|
||||
|
||||
install = mpOption.created || function() {}
|
||||
install = function() {
|
||||
mpOption.created && mpOption.created.call(this)
|
||||
Object.keys(mpOption.methods).forEach(key => {
|
||||
if(typeof mpOption.methods[key] === 'function'){
|
||||
this[key] = mpOption.methods[key].bind(this)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
uninstall = mpOption.detached || function() {}
|
||||
|
||||
|
@ -59,6 +66,10 @@ class Element extends WeElement {
|
|||
mpOption.ready && mpOption.ready.call(this)
|
||||
}
|
||||
|
||||
triggerEvent = function(name, data) {
|
||||
this.fire(name, data)
|
||||
}
|
||||
|
||||
setData = setData
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ function css() {
|
|||
}
|
||||
function render() {
|
||||
|
||||
return h('span',null,[`my-child`])
|
||||
return h('span',null,[`I am child component`])
|
||||
|
||||
}
|
||||
// components/my-child/my-child.js
|
||||
|
@ -49,7 +49,14 @@ class Element extends WeElement {
|
|||
|
||||
afterUpdate() {}
|
||||
|
||||
install = mpOption.created || function() {}
|
||||
install = function() {
|
||||
mpOption.created && mpOption.created.call(this)
|
||||
Object.keys(mpOption.methods).forEach(key => {
|
||||
if(typeof mpOption.methods[key] === 'function'){
|
||||
this[key] = mpOption.methods[key].bind(this)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
uninstall = mpOption.detached || function() {}
|
||||
|
||||
|
@ -58,6 +65,10 @@ class Element extends WeElement {
|
|||
mpOption.ready && mpOption.ready.call(this)
|
||||
}
|
||||
|
||||
triggerEvent = function(name, data) {
|
||||
this.fire(name, data)
|
||||
}
|
||||
|
||||
setData = setData
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
<!--components/my-child/my-child.wxml-->
|
||||
<text>my-child</text>
|
||||
<text>I am child component</text>
|
||||
|
|
|
@ -9,7 +9,7 @@ function css() {
|
|||
}
|
||||
function render() {
|
||||
|
||||
return h('div',null,[h('my-child',null,[]),h('div',{'ontap': this.myMethods},[`my-ele`])])
|
||||
return h('div',null,[h('button',{'ontap': this.myMethods},[`Click me will log dntzhang to the console panel`]),h('my-child',null,[])])
|
||||
|
||||
}
|
||||
// components/my-ele/my-ele.js
|
||||
|
@ -33,7 +33,7 @@ const mpOption = Component({
|
|||
*/
|
||||
methods: {
|
||||
myMethods: function() {
|
||||
console.log('myMethods')
|
||||
this.triggerEvent('myevent', { name: 'dntzhang' })
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -51,7 +51,14 @@ class Element extends WeElement {
|
|||
|
||||
afterUpdate() {}
|
||||
|
||||
install = mpOption.created || function() {}
|
||||
install = function() {
|
||||
mpOption.created && mpOption.created.call(this)
|
||||
Object.keys(mpOption.methods).forEach(key => {
|
||||
if(typeof mpOption.methods[key] === 'function'){
|
||||
this[key] = mpOption.methods[key].bind(this)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
uninstall = mpOption.detached || function() {}
|
||||
|
||||
|
@ -60,6 +67,10 @@ class Element extends WeElement {
|
|||
mpOption.ready && mpOption.ready.call(this)
|
||||
}
|
||||
|
||||
triggerEvent = function(name, data) {
|
||||
this.fire(name, data)
|
||||
}
|
||||
|
||||
setData = setData
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<view>
|
||||
<my-child />
|
||||
<view bindtap="myMethods">my-ele</view>
|
||||
<button bindtap="myMethods">Click me will log dntzhang to the console panel</button>
|
||||
<my-child />
|
||||
</view>
|
||||
|
|
|
@ -9,9 +9,9 @@ function css() {
|
|||
}
|
||||
function render() {
|
||||
const { logs } = Object.assign({}, this.data, this.props)
|
||||
return h('div',{'class': `container log-list`},[ logs.map((log,index)=>{
|
||||
return h('div',{'class': `container log-list `},[ logs.map((log,index)=>{
|
||||
return h('span',{'class': `log-item`},[`${index + 1}. ${log}`])
|
||||
}),h('my-ele',null,[])])
|
||||
}),h('my-ele',{'onmyevent': this.myEventHandler},[])])
|
||||
|
||||
}
|
||||
//logs.js
|
||||
|
@ -27,6 +27,10 @@ const mpOption = Page({
|
|||
return util.formatTime(new Date(log))
|
||||
})
|
||||
})
|
||||
},
|
||||
myEventHandler: function (evt) {
|
||||
//output -> dntzhang
|
||||
console.log(evt.detail.name)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
<block wx:for="{{logs}}" wx:for-item="log">
|
||||
<text class="log-item">{{index + 1}}. {{log}}</text>
|
||||
</block>
|
||||
<my-ele />
|
||||
<my-ele bindmyevent="myEventHandler" />
|
||||
</view>
|
||||
|
|
Loading…
Reference in New Issue