[英]How to pass a variable in form action url in vuejs
I am trying to pass a variable url in form action but couldn't do so with the following code:我正在尝试在表单操作中传递变量 url 但无法使用以下代码执行此操作:
<form action="${url}/auth/login_student" method="POST">
....</form>
EDIT: And in script tag编辑:在脚本标签中
<script>
export default {
data() {
return{
url: process.env.VUE_APP_URL
}
}
}
</script>
I am importing the URL from .env
which is 2 folders above this file in hirerachy but it is showing the process.env.VUE_APP_URL is undefined我正在从
.env
导入 URL,它是hirerachy中此文件上方的2个文件夹,但它显示 process.env.VUE_APP_URL 未定义
My .env
file code:我的
.env
文件代码:
VUE_APP_URL=http://localhost:5000
You have to use v-bind
to set action
to a JavaScript expression.您必须使用
v-bind
将action
设置为 JavaScript 表达式。 You can then use a template string .然后,您可以使用模板字符串。
<form :action="`${url}/auth/login_student`" method="POST">
^ ^ ^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.