composition-api.uvue 6.2 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
  }
38

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

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

DCloud-WZF's avatar
DCloud-WZF 已提交
276 277 278 279
    const url = e.url!.includes('/') ? e.url : `${e.url}/${e.url}`
    uni.navigateTo({
      url: `/pages/composition-api/${id}/${url}`,
    })
280 281 282 283 284 285 286 287
  }
</script>

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