当前位置: 首页 > news >正文

企业网站托管推广平台排行榜

企业网站托管,推广平台排行榜,做阿里云网站的公司吗,定做app需要多少钱一、背景 之前在做录制回放平台的时候,需要前端展示子调用信息,子调用是一个请求列表数组结构,jsoneditor对数组的默认展示结构是[0].[1].[2]..的方式,为了达到如下的效果,必须用到 onNodeName的钩子函数,…

一、背景

之前在做录制回放平台的时候,需要前端展示子调用信息,子调用是一个请求列表数组结构,jsoneditor对数组的默认展示结构是[0].[1].[2]..的方式,为了达到如下的效果,必须用到 onNodeName的钩子函数,因此深入调研了下vue3如何集成jsoneditor

最后做出来的效果图 alt

onNodeName的参考文档 https://github.com/josdejong/jsoneditor/blob/master/docs/api.md alt

二、参考方案

json-editor-vue3 感谢这位老哥的方案,我看了下源码,没有满足我的需要,核心就是属性需要自己加,因此我拿着他的代码改了下

三、代码实现

  • 安装依赖 jsoneditor
npm install --save jsoneditor

jsoneditor是个开源的js的组件,参考文档 https://github.com/josdejong/jsoneditor

  • 编写组件

目录结构如下 alt

vue3-json-editor.tsx: 其中options的定义是完全参考jsoneditor的api文档的,具体需要什么功能,自己去实现对应的options即可!

import { ComponentPublicInstance, defineComponent, getCurrentInstance, onMounted, reactive, watch } from 'vue'
// @ts-ignore
// eslint-disable-next-line import/extensions
import JsonEditor from 'jsoneditor';
import 'jsoneditor/dist/jsoneditor.min.css';
// eslint-disable-next-line import/prefer-default-export
export const Vue3JsonEditor = defineComponent({
  props: {
    modelValue: [StringBooleanObjectArray],
    showBtns: [Boolean],
    expandedOnStart: {
      typeBoolean,
      defaultfalse
    },
    navigationBar: {
      typeBoolean,
      defaulttrue
    },
    mode: {
      typeString,
      default'tree'
    },
    modes: {
      typeArray,
      default () {
        return ['tree''code''form''text''view']
      }
    },
    lang: {
      typeString,
      default'en'
    },
    onNodeName: {
      typeFunction,
      default()=>{}
    }
  },
  setup (props: any, { emit }) {
    const root = getCurrentInstance()?.root.proxy as ComponentPublicInstance

    const state = reactive({
      editornull as any,
      errorfalse,
      json: {},
      internalChangefalse,
      expandedModes: ['tree''view''form'],

      uid`jsoneditor-vue-${getCurrentInstance()?.uid}`
    })

    watch(
      () => props.modelValue as unknown as any,
      async (val) => {
        if (!state.internalChange) {
          state.json = val
          // eslint-disable-next-line no-use-before-define
          await setEditor(val)
          state.error = false
          // eslint-disable-next-line no-use-before-define
          expandAll()
        }
      }, { immediatetrue })

    onMounted(() => {
      //这个options的定义是完全参考jsoneditor的api文档的
      const options = {
        mode: props.mode,
        modes: props.modes,
        onChange () {
          try {
            const json = state.editor.get()
            state.json = json
            state.error = false
            // eslint-disable-next-line vue/custom-event-name-casing
            emit('json-change', json)
            state.internalChange = true
            emit('input', json)
            root.$nextTick(function ({
              state.internalChange = false
            })
          } catch (e) {
            state.error = true
            // eslint-disable-next-line vue/custom-event-name-casing
            emit('has-error', e)
          }
        },
        onNodeName(v: object) {
          // eslint-disable-next-line vue/custom-event-name-casing
            return props.onNodeName(v);
        },

        onModeChange () {
          // eslint-disable-next-line no-use-before-define
          expandAll()
        },
        navigationBar: props.navigationBar
      }
      state.editor = new JsonEditor(
        document.querySelector(`#${state.uid}`),
        options,
        state.json
      )

      // eslint-disable-next-line vue/custom-event-name-casing
      emit('provide-editor', state.editor)
    })

    function expandAll ({
      if (props.expandedOnStart && state.expandedModes.includes(props.mode)) {
        (state.editor as any).expandAll()
      }
    }

    function onSave ({
      // eslint-disable-next-line vue/custom-event-name-casing
      emit('json-save', state.json)
    }

    function setEditor (value: any): void {
      if (state.editor) state.editor.set(value)
    }

    return () => {
      // @ts-ignore
      // @ts-ignore
      return (
        <div>
          <div id={state.uid} class={'jsoneditor-vue'}></div>
        </div>

      )
    }
  }
})

style.css

.ace_line_group {
  text-align: left;
}
.json-editor-container {
  display: flex;
  width100%;
}
.json-editor-container .tree-mode {
  width50%;
}
.json-editor-container .code-mode {
  flex-grow1;
}
.jsoneditor-btns {
  text-align: center;
  margin-top10px;
}
.jsoneditor-vue .jsoneditor-outer {
  min-height150px;
}
.jsoneditor-vue div.jsoneditor-tree {
  min-height350px;
}
.json-save-btn {
  background-color#20a0ff;
  border: none;
  color#fff;
  padding5px 10px;
  border-radius5px;
  cursor: pointer;
}
.json-save-btn:focus {
  outline: none;
}
.json-save-btn[disabled] {
  background-color#1d8ce0;
  cursor: not-allowed;
}
code {
  background-color#f5f5f5;
}

index.ts

export * from './vue3-json-editor';

四、如何使用

<template>
  <div class="container">
    <Vue3JsonEditor
        v-model="json"
        mode='view'
        :show-btns="true"
        :on-node-name="onNodeName"
    />
  </div>
</
template>

<script lang="ts" setup>
import {computed,} from 'vue'
import {Vue3JsonEditor} from "@/components/json-editor";


const props = defineProps({
  record: {
    typeObject,
    default() {
      return {
        request: undefined,
      };
    },
  },
});

const json=computed(()=>{
  const {record} = props;
  return record.subInvocations;
});

// eslint-disable-next-line consistent-return
const onNodeName = (node: {
    value: anytypeany
})=>{
  if (node.type==='object' && node.value.identity) {
    return node.value.identity;
  }
  return undefined;
}

</script>

<script lang="ts">
export default {
  name: 'Invocations',
};
</
script>


<style scoped lang="less">
.container {
  padding: 0 20px 20px 20px;
}
</style>

本文由 mdnice 多平台发布

http://www.hengruixuexiao.com/news/55466.html

相关文章:

  • 网站是由什么构成的网站seo优化方法
  • 做手机网站一般要多少钱提高工作效率的方法有哪些
  • 文件夹里内容做网站的分类免费产品推广网站
  • 有什么做任务接单赚钱网站2345网址导航浏览器
  • 免费学习做网站外贸营销网站建站
  • 美国做试管婴儿 网站长春网站优化团队
  • php中文网电商seo与sem是什么
  • 安徽网站建设网络公司优化设计六年级上册数学答案
  • wordpress未登录用户重定向seo推广优化的方法
  • 网站模板下载后如何使用外国黄冈网站推广平台
  • 请人帮忙做淘宝网站多少钱seo流量工具
  • 深圳营销型网站方案百度关键词推广一年多少钱
  • 咨询网站开发长春头条新闻今天
  • 做网站网站如何定位中山网站建设公司
  • 政府行业网站建设方案谷歌seo营销
  • 网站开发论文指导记录电商代运营公司排名
  • 常州网站建设公司报价关键词排名优化易下拉排名
  • 网站托管服务 重庆产品推广
  • 桂城网站制作seo怎么推广
  • 赣州优化公司重庆seo杨洋
  • 网站 搭建 公司百度seo推广工具
  • 公司做网站比较好的平台广州最新疫情
  • 广东建筑企业100强汕头seo建站
  • 页面有哪几个网站可以做便宜的seo网络营销推广
  • 基于web的旅游网站建设百度站长平台网站提交
  • 西安优化网站技术谷歌怎么投放广告
  • 做网站需要用到什么技术网站软文是什么
  • 广州网站建设外包企业营销策略分析论文
  • 做土建资料有什么网站没网站策划书
  • thinphp 做外贸网站无锡百姓网推广