是否可以在 Vue.js 中使用 python 脚本? [英] Is it possible to use a python script in Vue.js?

查看:473
本文介绍了是否可以在 Vue.js 中使用 python 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我无法在 Vue.js 中实例化子进程.有没有办法在 Vue.js (2.x) 中执行 python 脚本?

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 严格来说是一个客户端框架,除非从 Nuxt.js 中使用.如果您不使用 Nuxt,则需要某种类型的服务器(无论是 Python 或 Node 还是其他),并且可以在需要时调用 Python 脚本.如果您使用 Nuxt,您可以调用 Node 的 child_process.spawn(或 exec,或 spawnSync 或 execSync)来运行 Python 脚本(请参阅 这些文档).最后一种选择是将您的 python 转换为 JS 或将其编译为 WebAssembly,但听起来您想要做的是运行服务器端脚本,因此这对您不起作用.我的建议是从 Python 服务器(或其他可以执行 Python 的服务器)为您的 Vue 应用程序提供服务.

Vue is strictly a client-side framework, except when being used from 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. 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). 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. My recommendation would be to serve your Vue app from a Python server (or some other server that can exec Python).

这篇关于是否可以在 Vue.js 中使用 python 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆