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

企业网站托管拓客软件哪个好用

企业网站托管,拓客软件哪个好用,十大赚钱小程序,做个人网站怎么赚钱一、背景 之前在做录制回放平台的时候,需要前端展示子调用信息,子调用是一个请求列表数组结构,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.ds6.com.cn/news/40685.html

相关文章:

  • 二级域名做网站好不好网络营销策划方案的目的
  • 镇江高端网站建设工作室域名备案查询
  • 黑龙江做网站公司本地推广最有效的方法
  • 优化调整疫情防控相关措施百度爱采购优化
  • 展馆门户网站建设优化大师手机版下载
  • 做伦理电影网站邯郸网站seo
  • 北海手机网站制作长沙做网站推广公司咨询
  • 做网站价格公司百度收录软件
  • 商业网站初期建设资金预算舆情服务公司
  • 一级a做囗爰片免费网站网站推广优化怎样
  • 用dw做的网站容易变形站长之家seo工具
  • 网站图片在手机上做多大最清晰b站推广网站2023
  • 个人网店和网站的区别网站域名ip查询
  • 怎么做传奇网站seo专业术语
  • 做类似交易猫的网站百度 营销推广怎么操作
  • 宁波产品网站设计模板百度收录工具
  • 可靠的邢台做网站女生学网络营销这个专业好吗
  • 智联招聘网站怎么做微招聘电商广告网络推广
  • 兰州电商平台网站建设巨量数据官网
  • 办理网站备案多少钱碉堡了seo博客
  • 用织梦系统怎么做网站曲靖seo
  • 个人工作室网站怎么做搜索引擎优化文献
  • 视频素材网站怎么建搜索引擎的工作原理分为
  • 潍坊专业网站建设公司微信公众号推广方法有哪些
  • 苏州品牌网站建设网站备案流程
  • 记事本怎么做网站湖南做网站的公司
  • 怎么样在百度做网站企点
  • 门户网站群建设汕头seo公司
  • 济南企业建站平台大二网页设计作业成品
  • 天津市建设监理协会网站网页怎么搜索关键词