2

I am trying to create search bar(form), but I need it to have pretty URL but I am using Vue-router so my app.js looks like this

let Search = Vue.component('search', require('./components/Search.vue'));
const routes = [
    { path: '/protocols/:param', component: Search },
]

now functionally when I type /protocols/test I get my desired results, but I am not sure how to create a form so when I type something to redirect me to that route /protocols/:param since my page is vue component

<form action="/protocols/?what goes here?">
    <input type="text" placeholder="Search..." class="" name="" id="search">
</form>

since all tutorials are made for search on the same page, but I need to dedicate one for results

1 Answer 1

2

You can use v-model to assign the input value to your data and use a computed property to generate the URL action like this:

<form :action="urlAction">
    <input type="text" placeholder="Search..." class="" name="" id="search" v-model='search'>
</form>

Now use data and computed props to build the dynamic URL

data () {
  return {
    search: ''
  }
},

computed: {
  urlAction () {
    return "/protocols/" + this.search
   }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.