<!-- index.vue -->
<button type="primary"
data-text="逻辑层方法调用成功"
@click="aly.handleEvent">{{aly.text}}</button>
// aly.sjs
export default {
text: 'SJS_Button-text',
handleEvent: function(event, ownerComponent) {
// 更改背景颜色
event.instance.setStyle({ 'background-color': '#e64340' });
// 调用逻辑层方法
event.instance.callMethod('printLog', event)
}
}
// index.vue
<script module="aly" lang="sjs" src="./aly.sjs"></script>
<script setup>
import { shallowReactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
const data = shallowReactive({
text: 'Button'
})
onLoad(() => console.log('pageLoad'))
defineExpose({
printLog: args => {
console.log(args)
}
})
</script>