vue3-json-schema-form中StringField.vue报错 `<script setup>` cannot contain ES module exports vue/no-e

5,602次阅读
没有评论

共计 2086 个字符,预计需要花费 6 分钟才能阅读完成。

报错 cannot contain ES module exports vue/no-export-in-script-setup

vue3-json-schema-form 课程中 StringField.vue 照着打报错
原代码如下:

template>
  input type="text" :value="value" @input="handleChange" />
template>
`script lang="ts" setup="props">
import { ref } from 'vue'
import { FiledPropsDfine, Schema } from '../types'
export default {
  props: FiledPropsDfine,
}
declare const props: {
  
  value: any
  onChange: (v: string) => void
  schema: Schema
}

export const handleChange = (e: any) => {
  console.log(e)
  props.onChange(e.target.value)
}
script>

修改后代码如下:

template>
  input type="text" :value="value" @input="handleChange" />
template>
`script lang="ts" setup="props">
import { FiledPropsDfine, Schema } from '../types'
declare const props: FiledPropsDfine & {
  
  value: any
  onChange: (v: string) => void
  schema: Schema
}
const handleChange = (e: any) => {
  console.log(e)
  props.onChange(e.target.value)
}
script>

type.ts 文件代码片段如下:

import {SchemaRefs} from 'ajv/dist/compile'
import {PropType} from 'vue'
export enum SchemaTypes {
  'NUMBER' = 'number',
  'INTEGER' = 'intrger',
  'STRING' = 'string',
  'OBJECT' = 'object',
  'ARRSY' = 'array',
  'BOOLEAN' = 'boolean',
}

type SchemaRef = {$ref: string} // 预先定义 可以使用 $ref 引用 schema

// type Schema = any
export interface Schema {
  type: SchemaTypes | string // 加上 string 有利于类型的校验 要不然只能用 SchemaTypes.NUMBER 来使用类型
  const?: any
  format?: string
  default?: any
  properties?: {[key: string]: Schema | {$ref: string}
  }
  items?: Schema | Schema[] | SchemaRefs
  dependencies?: {[key: string]: string[] | Schema | SchemaRef}
  oneOf?: Schema[]
  anyOf?: Schema[]
  allOf?: Schema[]
  //   vjsf?: VueJsonSchemaConfig
  required?: string[]
  enum?: any[]
  enumKeyValue?: any[]
  additionalProperties?: any
  additionalItems?: Schema
}

export const FiledPropsDfine = {
  schema: {type: Object as PropTypeSchema>,
    required: true,
  },
  value: {required: true,},
  onChange: {type: Function as PropType void>,
    required: true,
  },
  rootSchema: {type: Object as PropTypeSchema>,
    required: true,
  },
} as const

主要问题就是说 script 标签中加上 setup,代码块中不能再出现 export default 关键字,将该部分代码

export default {props: FiledPropsDfine,}
declare const props: {
  // 向 ts 声明 props 的定义
  value: any
  onChange: (v: string) => void
  schema: Schema
}

修改为:

declare const props: FiledPropsDfine & {
  // 向 ts 声明 props 的定义
  value: any
  onChange: (v: string) => void
  schema: Schema
}

原文地址: vue3-json-schema-form 中 StringField.vue 报错 `

正文完
 0
Yojack
版权声明:本篇文章由 Yojack 于2024-10-02发表,共计2086字。
转载说明:
1 本网站名称:优杰开发笔记
2 本站永久网址:https://yojack.cn
3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5 本站所有内容均可转载及分享, 但请注明出处
6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
7 站长邮箱:laylwenl@gmail.com
评论(没有评论)