I have a web application with frontend Vue js and backend Laravel. I have to show a dropdown for selecting timezone which will be populated from Laravel backend in blade file. I have a scoped slot in my vue component which can bind that dropdown list providing reactive property selectedId
which I can bind to select element as v-model
. The problem here is that the select element sets to a value passed from reactive property selectedId
but on changing select option the new value is not passed back to that reactive property selectedId
. So I think I am not able to bind the reactive property selectedId
two way. How can I fix this?
Following is my code
NewProject.vue
<template>
<div>
<div class="row">
<div class="col-md-12">
<fieldset>
<div class="form-group">
<label class="col-sm-2 control-label">Select Project Time Zone</label>
<slot name="timezone" :selectedId="selectedId"></slot>
{{selectedId}}
</div>
</fieldset>
<button v-on:click="getSelectedTimeZone">Click Me</button>
</div>
</div>
</div>
</template>
<script>
export default{
data(){
return {
selectedId: 'Pacific/Fiji'
}
},
methods: {
getSelectedTimeZone: function (event) {
alert(this.selectedId);
}
},
}
</script>
<style scoped>
</style>
newProject.js
require('./bootstrap');
import NewProject from "../../../assets/js/components/Template/NewProject.vue";
import GlobalMixin from "../../../assets/js/mixins/GlobalMixin";
const newProject=new Vue({
el:'#newProject',
mixins:[
GlobalMixin,
],
components:{
'new-project':NewProject,
},
methods:{
},
mounted(){
},
});
new_project.blade.php
@extends('layouts.headless')
@section('content')
<new-project>
<template slot="timezone" slot-scope='data'>
<select v-model="data.selectedId">
@foreach ($timezone_list['Pacific'] as $key=>$value)
<option value="{{$key}}">{!! $value !!}</option>
@endforeach
</select>
</template>
</new-project>
@stop