简体   繁体   English

是否可以在 Vue.js 中使用 python 脚本?

[英]Is it possible to use a python script in Vue.js?

I observe that I cannot instantiate a child process in Vue.js. Is there any way to execute a python script in Vue.js (2.x)?我观察到我无法在 Vue.js 中实例化子进程。有什么方法可以在 Vue.js (2.x) 中执行 python 脚本吗?

Vue is strictly a client-side framework, except when being used from Nuxt.js. Vue 严格来说是一个客户端框架,除了从 Nuxt.js 使用时。 If you're not using Nuxt, you would need a server of some sort (whether Python or Node or something else), and that could call a python script when needed.如果您不使用 Nuxt,则需要某种服务器(无论是 Python 还是 Node 或其他),并且可以在需要时调用 python 脚本。 If you are using Nuxt, you could call Node's child_process.spawn (or exec, or spawnSync or execSync) to run a Python script (see these docs ).如果您使用 Nuxt,您可以调用 Node 的child_process.spawn (或 exec,或 spawnSync 或 execSync)来运行 Python 脚本(请参阅这些文档)。 One last alternative would be transpiling your python to JS or compiling it to WebAssembly, but it sounds like what you want to do is run a server-side script, so that wouldn't work for you.最后一种选择是将您的 python 转换为 JS 或将其编译为 WebAssembly,但听起来您想要做的是运行服务器端脚本,所以这对您不起作用。 My recommendation would be to serve your Vue app from a Python server (or some other server that can exec Python).我的建议是从 Python 服务器(或其他可以执行 Python 的服务器)为您的 Vue 应用程序提供服务。

In theory you can add pyscript, see: https://pyscript.net/理论上可以加上pyscript,见: https://pyscript.net/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM