The way that you've solved it, you're not really using VueJS, and flat javascript would make more sense. A more VueJS approach would be something like this: (presuming you're writing in a Blade View, this would need to be in a )
new Vue({
data: function() {
return {
form: {
baseAction: "/subjects/{{ $lesson->subject->slug }}/",
chosenAction: '',
}
}
},
computed: {
computedAction: function() {
return this.form.baseAction + this.form.chosenAction;
}
}
});
Now for your form:
<form action="computedAction">
And for your select:
<select v-model="form.chosenAction">
The onchange isn't necessary here as we're binding the value of the selected to the chosenAction property of the form object. We then use the computedAction property (which is a computed value, of course) to dictate the action of our form.
EDIT - When using a transpiled vuejs approach with single file components:
If you want vuejs to be responsible for the life-cycle of the form, then you can use a single file component:
<template>
<form id="tagForm" method="POST" action="computedAction">
<input type="hidden" name="_token" value="token"/>
<div class="select">
<select v-model="form.chosenAction">
<option value="">Tags</option>
<option v-for="tag in tags" value="tag.id"> {{tag.title}} </option>
</select>
</div>
</form>
</template>
<script>
export default {
props: ['tags', 'slug', 'token']
data: function() {
return {
form: {
chosenAction: ''
}
}
},
computed: {
computedAction: function() {
return `/subjects/${slug}/${this.form.chosenAction}`
}
}
}
</script>
Now in your app.js file you need to tell Vue about this new component so you can use it in your blade template. This needs to come after you use import Vue from 'vue' in your app.js file.
import MyCoolForm from './path/to/my/cool/form.js';
Vue.component('v-mycoolform', MyCoolForm);
Now in your blade template, you can pass properties to this component:
<v-mycoolform :slug="{{$lesson->subject->slug}}" :token="{{csrf_token()}}" :tags="{{json_encode($tags)}}"/>