rax-link
Version:
Link component for Rax.
76 lines (67 loc) • 1.76 kB
JavaScript
"use strict";
var _fmtEvent = _interopRequireDefault(require("./fmtEvent"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* miniappHref value:navigate:abc?a=1 redirect:abc?a=1 switchTab:a/b/c navigateBack:2
* mpHref for backward compatibility
*/
console.warn('组件所依赖的 rax-link 版本较旧,请尽快重新构建发布该组件');
Component({
data: {},
properties: {
className: {
type: String,
value: ''
},
styleSheet: {
type: String,
value: ''
},
mpHref: {
type: String,
value: ''
},
miniappHref: {
type: String,
value: ''
}
},
options: {
styleIsolation: 'apply-shared'
},
methods: {
onTap: function onTap(e) {
var event = (0, _fmtEvent.default)(this.properties, e); // onPress for backward compatibility
this.triggerEvent('onPress', event.detail);
this.triggerEvent('onClick', event.detail);
var miniappHref = this.properties.miniappHref || this.properties.mpHref;
if (miniappHref) {
var splits = miniappHref.split(':');
var actionName = splits[0];
var target = splits[1] || actionName;
switch (actionName) {
case 'redirect':
wx.redirectTo({
url: target
});
break;
case 'switchTab':
wx.switchTab({
url: target
});
break;
case 'navigateBack':
wx.navigateBack({
delta: target
});
break;
case 'navigate':
default:
wx.navigateTo({
url: target
});
}
}
}
}
});