UNPKG

logic-helper

Version:

This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

37 lines (36 loc) 769 B
import { defineStore } from 'pinia'; import { store } from '@/common/js/app.js' import ws from '@/ws/index.js'; function transformData(data) { const result = [] for (let key in data) { const item = { value: key, label: key } if (data[key] && typeof data[key] === 'object') { item.children = transformData(data[key]) } result.push(item) } return result }; export const useDirectory = defineStore({ id: 'project-directory', // id必填,且需要唯一 state: () => { return { root: null }; }, actions: { init() { ws.getRootDir().then(res=>{ this.root = transformData(res); }) } }, });