native-view.uvue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <scroll-view style="flex: 1;">
  3. <view style="padding-bottom: 50px;">
  4. <!-- #ifndef APP-HARMONY -->
  5. <text class="tips">说明:如果本地无 uts 插件编译环境请提交打包自定义基座查看效果</text>
  6. <!-- #endif -->
  7. <!-- #ifdef APP-HARMONY -->
  8. <text class="tips"> </text>
  9. <!-- #endif -->
  10. <button type="primary" @tap="testCallMethod">调用组件方法</button>
  11. <!-- native-button 通过 native-view 绑定原生button 实现的UTS插件-标准模式组件 -->
  12. <native-button id="helloView" class="native-button" style="width: 200px; height: 100px;" :text="buttonText" @buttonTap="ontap"
  13. @load="onload"></native-button>
  14. <native-button-container></native-button-container>
  15. <!-- #ifndef APP-HARMONY -->
  16. <button type="primary" @click="gotoTimePicker">调用native-time-picker</button>
  17. <!-- #endif -->
  18. </view>
  19. </scroll-view>
  20. </template>
  21. <script>
  22. import { createNativeButtonContext } from "@/uni_modules/native-button";
  23. export default {
  24. data() {
  25. return {
  26. title: 'Hello',
  27. buttonText: "native-button",
  28. isLoad: false,
  29. clickCount: 0
  30. }
  31. },
  32. onLoad() {
  33. },
  34. methods: {
  35. ontap(e : UniNativeViewEvent) {
  36. uni.showToast({
  37. title: "按钮被点击了"
  38. })
  39. this.clickCount ++
  40. this.buttonText = "native-button"+this.clickCount
  41. },
  42. onload() {
  43. //标记已初始化 用于自动化测试
  44. this.isLoad = true
  45. },
  46. testCallMethod: function () {
  47. let context = createNativeButtonContext("helloView")
  48. context?.updateText("test code")
  49. },
  50. gotoTimePicker() {
  51. uni.openDialogPage({
  52. url: "/pages/component/native-view/native-view-time-picker-dialog",
  53. animationType: "fade-in"
  54. })
  55. }
  56. }
  57. }
  58. </script>
  59. <style>
  60. .tips {
  61. font-size: 14px;
  62. color: #BEBEBE;
  63. margin: 25px auto 25px auto;
  64. text-align: center;
  65. }
  66. .native-button {
  67. height: 100px;
  68. width: 100px;
  69. margin: 25px auto 25px auto;
  70. }
  71. </style>