uniapp renderjs

打印 上一主题 下一主题

主题 1015|帖子 1015|积分 3045

  1. <template>
  2.         <view class="content">
  3.                 <p>count:{{count}}</p>
  4.                 <p>useCountStore.count:{{useCountStore.count}}</p>
  5.                 <p>info:{{info}}</p>
  6.                 <button @click="add" size="mini">add()</button>
  7.                 <button @click="addN(3)" size="mini">addN(3)</button>
  8.                 <button @click="useCountStore.add" size="mini">useCountStore.add()</button>
  9.                 <button @click="useCountStore.addN(3)" size="mini">useCountStore.addN(3)</button>
  10.                 <button @click="testRenderjs.add" size="mini">testRenderjs.add()</button>
  11.                 <button @click="testRenderjs.addN" size="mini">testRenderjs.addN()</button>
  12.                 <button @click="testRenderjs.changeInfo" size="mini">testRenderjs.changeInfo()</button>
  13.                 <!-- testRenderjs为renderjs中的名字 -->
  14.                 <view id="testRenderjs" :info="info" :change:info="testRenderjs.receiveInfo" :count="useCountStore.count"
  15.                         :change:count="testRenderjs.receiveCount">
  16.                 </view>
  17.         </view>
  18. </template>
  19. <script lang="ts">
  20.         import { ref, onMounted, computed } from 'vue'
  21.         import useStore from "@/stores";
  22.         export default {
  23.                 setup() {
  24.                         const { useCountStore } = useStore();
  25.                         const count = computed(() => { return useCountStore.count || 0 });
  26.                         const add = useCountStore.add;
  27.                         const addN = useCountStore.addN;
  28.                         const info = ref('一开始的数据');
  29.                         function receiveRenderData(val : any) {
  30.                                 console.log('renderjs返回的值-->', val);
  31.                                 info.value = val;
  32.                         }
  33.                         onMounted(() => {
  34.                                 setTimeout(() => {
  35.                                         info.value = '变化后的数据';
  36.                                 }, 1000);
  37.                         })
  38.                         // 返回值会暴露给模板和其他的选项式 API 钩子
  39.                         return {
  40.                                 useCountStore,
  41.                                 count,
  42.                                 info,
  43.                                 add,
  44.                                 addN,
  45.                                 receiveRenderData
  46.                         }
  47.                 },
  48.         }
  49. </script>
  50. <script module="testRenderjs" lang="renderjs">
  51.         import {
  52.                 ref
  53.         } from 'vue'
  54.         export default {
  55.                 setup() {
  56.                         const testRenderjsData = ref('我是来自renderjs的数据');
  57.                         // 发送数据到逻辑层
  58.                         function changeInfo(e, ownerVm) {
  59.                                 ownerVm.callMethod('receiveRenderData', testRenderjsData.value);
  60.                         }
  61.                         // 接收逻辑层发送的数据
  62.                         function receiveInfo(newValue, oldValue) {
  63.                                 console.log(newValue, oldValue, 'info----------------');
  64.                         }
  65.                         // 调用逻辑层函数
  66.                         function add(e, ownerVm) {
  67.                                 ownerVm.callMethod('add');
  68.                                 // ownerVm.callMethod('useCountStore.add'); // useless
  69.                                 // ownerVm.callMethod('useCountStore/add'); // useless
  70.                         }
  71.                         function addN(e, ownerVm) {
  72.                                 ownerVm.callMethod('addN', 3);
  73.                         }
  74.                         // 接收逻辑层发送的数据
  75.                         function receiveCount(newValue, oldValue) {
  76.                                 console.log(newValue, oldValue, 'count----------------');
  77.                         }
  78.                         return {
  79.                                 testRenderjsData,
  80.                                 add,
  81.                                 addN,
  82.                                 changeInfo,
  83.                                 receiveInfo,
  84.                                 receiveCount
  85.                         }
  86.                 }
  87.         }
  88. </script>
  89. <style>
  90.         .content {
  91.                 display: flex;
  92.                 flex-direction: column;
  93.                 align-items: center;
  94.                 justify-content: center;
  95.         }
  96. </style>
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

道家人

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表