Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>vscode-yapi-transformNew to Visual Studio Code? Get it now.

vscode-yapi-transform

qmvscode

|
2 installs
| (0) | Free
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

vscode-yapi-transform

yapi转换前端代码插件

安装

1.npm install -g yo generator-code 2.yo code

vscode插件开发使用vue需要解决跨域问题(参考文章[https://blog.csdn.net/u010750137/article/details/127991644])

1.路径转换 function getUri(webview: Webview, extensionUri: Uri, pathList: string[]) { return webview.asWebviewUri(Uri.joinPath(extensionUri, ...pathList)); }

function getNonce() {
  let text = "";
  const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  for (let i = 0; i < 32; i++) {
    text += possible.charAt(Math.floor(Math.random() * possible.length));
  }
  return text;
}

2.修改资源路径 // The CSS file from the Vue build output const stylesUri = getUri(webview, extensionUri, ["dist", "assets", "index.css"]); // The JS file from the Vue build output const scriptUri = getUri(webview, extensionUri, ["dist", "assets", "index.js"]);

const nonce = getNonce();

webview里面需要解决vue如何与vscode进行通信

1.安装npm install --save @types/vscode-webview 2.通过创建vscodeApi实例调用postMessage方法

vscode生成本地文件到用户工作区

1.无法使用fs模块,需要借助vscode.workspace.fs模块 2.需要通过vscode.workspace.workspaceFolders获取用户工作区路径 3.文件读取需要对数据进行Unit8Array与字符串转换 // string转unit8Array function stringToUint8Array(str: any) { var arr = []; for (var i = 0, j = str.length; i < j; ++i) { arr.push(str.charCodeAt(i)); } var tmpUint8Array = new Uint8Array(arr); return tmpUint8Array; }

// unit8Array转string
function Uint8ArrayToString(fileData: any) {
  var dataString = "";
  for (var i = 0; i < fileData.length; i++) {
    dataString += String.fromCharCode(fileData[i]);
  }
  return dataString;
}
  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2023 Microsoft