composition-api.uvue 5.6 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 53 54 55 56 57 58 59 60 61 62
  
  const list = [
      {
        id: 'basic',
        name: '基本使用',
        open: false,
        pages: [
          {
            name: 'defineProps',
            url: 'define-props',
            enable: false,
          },
          {
            name: 'defineEmits',
            url: 'define-emits',
            enable: false,
          },
          {
            name: 'defineExpose',
            url: 'define-expose',
            enable: false,
          },
          {
            name: 'defineOptions',
            url: 'define-options',
63
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
          },
          {
            name: 'defineSlots',
            url: 'define-slots',
            enable: false,
          },
          {
            name: 'useSlots',
            url: 'use-slots',
            enable: false,
          },
          {
            name: 'useAttrs',
            url: 'use-attrs',
            enable: false,
          },
        ] as PageItem[],
      }, {
82
        id: 'reactivity',
DCloud-WZF's avatar
DCloud-WZF 已提交
83 84 85 86 87 88
        name: '响应式',
        open: false,
        pages: [
          {
            name: 'ref',
            url: 'ref',
89
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
90 91 92 93
          },
          {
            name: 'computed',
            url: 'computed',
DCloud-WZF's avatar
DCloud-WZF 已提交
94
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
95 96 97 98
          },
          {
            name: 'reactive',
            url: 'reactive',
DCloud-WZF's avatar
DCloud-WZF 已提交
99
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
100 101 102 103
          },
          {
            name: 'readonly',
            url: 'readonly',
DCloud-WZF's avatar
DCloud-WZF 已提交
104
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
105 106 107 108
          },
          {
            name: 'watch',
            url: 'watch',
DCloud-WZF's avatar
DCloud-WZF 已提交
109
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
110 111 112 113
          },
          {
            name: 'watchEffect',
            url: 'watch-effect',
DCloud-WZF's avatar
DCloud-WZF 已提交
114
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128
          },
          {
            name: 'watchPostEffect',
            url: 'watch-post-effect',
            enable: false,
          },
          {
            name: 'watchSyncEffect',
            url: 'watch-sync-effect',
            enable: false,
          },
          {
            name: 'isRef',
            url: 'is-ref',
DCloud-WZF's avatar
DCloud-WZF 已提交
129
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
130 131 132 133
          },
          {
            name: 'unRef',
            url: 'un-ref',
DCloud-WZF's avatar
DCloud-WZF 已提交
134
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
135 136 137 138
          },
          {
            name: 'toRef',
            url: 'to-ref',
DCloud-WZF's avatar
DCloud-WZF 已提交
139
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
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
          },
          {
            name: 'toValue',
            url: 'to-value',
            enable: false,
          },
          {
            name: 'toRefs',
            url: 'to-refs',
            enable: false,
          },
          {
            name: 'isProxy',
            url: 'is-proxy',
            enable: false,
          },
          {
            name: 'isReactive',
            url: 'is-reactive',
            enable: false,
          },
          {
            name: 'isReadonly',
            url: 'is-readonly',
            enable: false,
          },
          {
            name: 'shallowRef',
            url: 'shallow-ref',
            enable: false,
          },
          {
            name: 'triggerRef',
            url: 'trigger-ref',
            enable: false,
          },
          {
            name: 'customRef',
            url: 'custom-ref',
            enable: false,
          },
          {
            name: 'shallowReactive',
            url: 'shallow-reactive',
            enable: false,
          },
          {
            name: 'shallowReadonly',
            url: 'shallow-readonly',
            enable: false,
          },
          {
            name: 'toRaw',
            url: 'to-raw',
            enable: false,
          },
          {
            name: 'markRaw',
            url: 'mark-raw',
            enable: false, // 暂不支持
          },
          {
            name: 'effectScope',
            url: 'effect-scope',
            enable: false,
          },
          {
            name: 'getCurrentScope',
            url: 'get-current-scope',
            enable: false,
          },
          {
            name: 'onScopeDispose',
            url: 'on-scope-dispose',
            enable: false,
          },
        ] as PageItem[],
217
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
218 219 220 221 222 223 224 225 226 227
    ] as PageList[]

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

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

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