vue3中使用unplugin-vue-define-options报错

 我的初始安装版本是 0.12.7

在使用vite3+vue3+js的项目中,使用unplugin-vue-define-options插件时,在vue文件中使用defineOptions时报错提示:

Internal server error: unplugin-vue-define-options TypeError: Cannot read properties of undefined (reading 'scriptSetupAst')

 我都按照官方引入使用的,但是提示没有这个无法使用。

百度都没查到问题,最后在github上看到有人也遇到同样问题
 https://github.com/sxzz/unplugin-vue-macros/issues/203

解决办法:
 降低插件版本到 0.12.2

安装命令:

pnpm i unplugin-vue-define-options@0.12.2 -D 

 最好先删除依赖再pnpm i 之后运行此命令,我试了两次才成功。

1. 安装 vue3-ace-editor ```shell npm install vue3-ace-editor ``` 2. 在需要使用的组件引入 ace-editor 组件 ```html <template> <AceEditor v-model="code" :options="options" mode="myCustomLanguage" :highlightActiveLine="true" :tabSize="2" theme="twilight" style="height: 500px;" /> </template> <script> import AceEditor from "vue3-ace-editor"; export default { components: { AceEditor, }, data() { return { code: "", options: { enableBasicAutocompletion: true, enableSnippets: true, enableLiveAutocompletion: true, }, }; }, mounted() { this.$nextTick(() => { this.code = "function myFunction() {\n console.log('Hello World!');\n}"; }); }, }; </script> ``` 3. 添加自定义语言 ```javascript import ace from "ace-builds"; import "ace-builds/src-noconflict/mode-javascript"; // 引入 JavaScript 语言模块 ace.define( "ace/mode/myCustomLanguage_highlight_rules", function (require, exports) { var oop = require("ace/lib/oop"); var TextHighlightRules = require("ace/mode/text_highlight_rules") .TextHighlightRules; var MyCustomLanguageHighlightRules = function () { // 注释 this.$rules["start"] = [ { token: "comment", regex: "//.*$", }, ]; // 关键字 this.$rules["start"].push({ token: "keyword", regex: "function", }); // 函数名 this.$rules["start"].push({ token: "entity.name.function", regex: "myFunction", }); // 字符串 this.$rules["start"].push({ token: "string", regex: "'|\"", next: "string", }); // 其他 this.$rules["start"].push({ defaultToken: "text", }); this.$rules.string = [ { token: "constant.language.escape", regex: /\\(?:['"\\]|[0-7]{3})/, }, { token: "string", regex: /['"]/, next: "start", }, { defaultToken: "string", }, ]; }; oop.inherits(MyCustomLanguageHighlightRules, TextHighlightRules); exports.MyCustomLanguageHighlightRules = MyCustomLanguageHighlightRules; } ); ace.define("ace/mode/myCustomLanguage", function (require, exports) { var oop = require("ace/lib/oop"); var TextMode = require("ace/mode/text").Mode; var MyCustomLanguageHighlightRules = require("./myCustomLanguage_highlight_rules") .MyCustomLanguageHighlightRules; var MyCustomLanguageMode = function () { this.HighlightRules = MyCustomLanguageHighlightRules; }; oop.inherits(MyCustomLanguageMode, TextMode); (function () { this.$id = "ace/mode/myCustomLanguage"; }).call(MyCustomLanguageMode.prototype); exports.Mode = MyCustomLanguageMode; }); ``` 4. 在组件引入自定义语言模块 ```javascript import "ace-builds/src-noconflict/mode-myCustomLanguage"; // 引入自定义语言模块 ``` 5. 完整代码 ```html <template> <AceEditor v-model="code" :options="options" mode="myCustomLanguage" :highlightActiveLine="true" :tabSize="2" theme="twilight" style="height: 500px;" /> </template> <script> import AceEditor from "vue3-ace-editor"; import "ace-builds/src-noconflict/mode-myCustomLanguage"; // 引入自定义语言模块 export default { components: { AceEditor, }, data() { return { code: "", options: { enableBasicAutocompletion: true, enableSnippets: true, enableLiveAutocompletion: true, }, }; }, mounted() { this.$nextTick(() => { this.code = "function myFunction() {\n console.log('Hello World!');\n}"; }); }, }; </script> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值