PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 19, 2022

[FIXED] How to pass a variable in form action url in vuejs

 August 19, 2022     action, environment-variables, forms, javascript, vue.js     No comments   

Issue

I am trying to pass a variable url in form action but couldn't do so with the following code:

<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

My .env file code:

VUE_APP_URL=http://localhost:5000

Solution

You have to use v-bind to set action to a JavaScript expression. You can then use a template string.

<form :action="`${url}/auth/login_student`" method="POST">
      ^        ^                         ^


Answered By - Decade Moon
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing