composition-api.uvue 5.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
  <!-- #endif -->
    <view class="uni-container">
      <uni-collapse>
        <template v-for="item in list" :key="item.id">
          <uni-collapse-item :title="item.name" class="item">
            <view class="uni-navigate-item" :hover-class="page.enable == false ? '' : 'is--active'"
              v-for="(page, key) in item.pages" :key="key" @click="goDetailPage(item.id, page)">
              <text class="uni-navigate-text"
                :class="page.enable == false ? 'text-disabled' : ''">{{ page.name }}</text>
            </view>
          </uni-collapse-item>
        </template>
      </uni-collapse>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

DCloud-WZF's avatar
DCloud-WZF 已提交
23
<script setup lang="uts">
24 25 26 27 28 29 30 31 32 33 34 35 36 37
  type PageItem = {
    name : string
    enable ?: boolean
    url ?: string
  }

  type PageList = {
    id : string
    name : string
    open : boolean
    pages : PageItem[]
    url ?: string
    enable ?: boolean
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  
  const list = [
      {
        id: 'basic',
        name: '基本使用',
        open: false,
        pages: [
          {
            name: 'defineProps',
            url: 'define-props',
            enable: false,
          },
          {
            name: 'defineEmits',
            url: 'define-emits',
DCloud-WZF's avatar
DCloud-WZF 已提交
53
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
54 55 56 57
          },
          {
            name: 'defineExpose',
            url: 'define-expose',
DCloud-WZF's avatar
DCloud-WZF 已提交
58
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
59 60 61 62
          },
          {
            name: 'defineOptions',
            url: 'define-options',
63
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
64 65 66 67
          },
          {
            name: 'defineSlots',
            url: 'define-slots',
DCloud-WZF's avatar
DCloud-WZF 已提交
68
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
69
          },
DCloud-WZF's avatar
DCloud-WZF 已提交
70 71 72 73 74
{
            name: 'defineModel',
            url: 'define-model',
            enable: true,
          },
DCloud-WZF's avatar
DCloud-WZF 已提交
75 76 77 78 79 80 81 82 83 84 85 86
          {
            name: 'useSlots',
            url: 'use-slots',
            enable: false,
          },
          {
            name: 'useAttrs',
            url: 'use-attrs',
            enable: false,
          },
        ] as PageItem[],
      }, {
87
        id: 'reactivity',
DCloud-WZF's avatar
DCloud-WZF 已提交
88 89 90 91 92 93
        name: '响应式',
        open: false,
        pages: [
          {
            name: 'ref',
            url: 'ref',
94
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
95 96 97 98
          },
          {
            name: 'computed',
            url: 'computed',
DCloud-WZF's avatar
DCloud-WZF 已提交
99
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
100 101 102 103
          },
          {
            name: 'reactive',
            url: 'reactive',
DCloud-WZF's avatar
DCloud-WZF 已提交
104
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
105 106 107 108
          },
          {
            name: 'readonly',
            url: 'readonly',
DCloud-WZF's avatar
DCloud-WZF 已提交
109
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
110 111 112 113
          },
          {
            name: 'watch',
            url: 'watch',
DCloud-WZF's avatar
DCloud-WZF 已提交
114
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
115 116 117 118
          },
          {
            name: 'watchEffect',
            url: 'watch-effect',
DCloud-WZF's avatar
DCloud-WZF 已提交
119
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
120 121 122 123
          },
          {
            name: 'watchPostEffect',
            url: 'watch-post-effect',
124
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
125 126 127 128
          },
          {
            name: 'watchSyncEffect',
            url: 'watch-sync-effect',
129
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
130 131 132 133
          },
          {
            name: 'isRef',
            url: 'is-ref',
DCloud-WZF's avatar
DCloud-WZF 已提交
134
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
135 136 137 138
          },
          {
            name: 'unRef',
            url: 'un-ref',
DCloud-WZF's avatar
DCloud-WZF 已提交
139
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
140 141 142 143
          },
          {
            name: 'toRef',
            url: 'to-ref',
DCloud-WZF's avatar
DCloud-WZF 已提交
144
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
145 146 147 148
          },
          {
            name: 'toValue',
            url: 'to-value',
DCloud-WZF's avatar
DCloud-WZF 已提交
149
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
150 151 152 153
          },
          {
            name: 'toRefs',
            url: 'to-refs',
DCloud-WZF's avatar
DCloud-WZF 已提交
154
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
155 156 157 158
          },
          {
            name: 'isProxy',
            url: 'is-proxy',
DCloud-WZF's avatar
DCloud-WZF 已提交
159
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
160 161 162 163
          },
          {
            name: 'isReactive',
            url: 'is-reactive',
DCloud-WZF's avatar
DCloud-WZF 已提交
164
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
165 166 167 168
          },
          {
            name: 'isReadonly',
            url: 'is-readonly',
DCloud-WZF's avatar
DCloud-WZF 已提交
169
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
170 171 172 173
          },
          {
            name: 'shallowRef',
            url: 'shallow-ref',
DCloud-WZF's avatar
DCloud-WZF 已提交
174
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
175 176 177 178
          },
          {
            name: 'triggerRef',
            url: 'trigger-ref',
DCloud-WZF's avatar
DCloud-WZF 已提交
179
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
180 181 182 183
          },
          {
            name: 'customRef',
            url: 'custom-ref',
DCloud-WZF's avatar
DCloud-WZF 已提交
184
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
185 186 187 188
          },
          {
            name: 'shallowReactive',
            url: 'shallow-reactive',
189
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
190 191 192 193
          },
          {
            name: 'shallowReadonly',
            url: 'shallow-readonly',
194
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
195 196 197 198
          },
          {
            name: 'toRaw',
            url: 'to-raw',
DCloud-WZF's avatar
DCloud-WZF 已提交
199
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
200 201 202 203 204 205 206 207 208
          },
          {
            name: 'markRaw',
            url: 'mark-raw',
            enable: false, // 暂不支持
          },
          {
            name: 'effectScope',
            url: 'effect-scope',
DCloud-WZF's avatar
DCloud-WZF 已提交
209
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
210 211 212 213
          },
          {
            name: 'getCurrentScope',
            url: 'get-current-scope',
214
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
215 216 217 218
          },
          {
            name: 'onScopeDispose',
            url: 'on-scope-dispose',
219
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
220 221
          },
        ] as PageItem[],
222
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
223 224 225 226 227 228 229 230 231 232
    ] as PageList[]

  const goDetailPage = (id : string, e : PageItem) => {
    if (e.enable == false) {
      uni.showToast({
        icon: 'none',
        title: '暂不支持',
      })
      return
    }
233

DCloud-WZF's avatar
DCloud-WZF 已提交
234 235 236 237
    const url = e.url!.includes('/') ? e.url : `${e.url}/${e.url}`
    uni.navigateTo({
      url: `/pages/composition-api/${id}/${url}`,
    })
238 239 240 241 242 243 244 245
  }
</script>

<style>
  .item {
    margin-bottom: 12px;
  }
</style>