当我在vue.js中alert(this.property_credentials.district)
时,我变空了
<select v-model="property_credentials.district" name="district" class="country selectpicker" id="selectCountry" data-size="10" data-show-subtext="true" data-live-search="true">
<option value="0">--Please select your district</option>
@foreach($districts as $district)
<optgroup label="{{$district->district}}">
@foreach($district->regions as $region)
<option value={{ $region}} {{ (old("district") == $region? 'selected':'') }}>{{ $region}}</option>
@endforeach
</optgroup>
@endforeach
如何将此值$region
传递给vue.js?
答案 0 :(得分:1)
循环的语法错误,vuejs中没有@foreach
,你必须使用v-for在模板中循环。它应该是这样的:
<select v-model="property_credentials.district" name="district" class="country selectpicker" id="selectCountry" data-size="10" data-show-subtext="true" data-live-search="true">
<option value="0">--Please select your district</option>
<div v-for="district in $districts">
<optgroup label="{{district->district}}">
<div v-for="region in district.regions">
<option value={{region}} {{ (old("district") == region? 'selected':'') }}>{{ $region}}</option>
</div>
</optgroup>
</div>
答案 1 :(得分:0)
您正在将两种不同的语法混合在一起,您正在使用带有VueJs的刀片代码。数据绑定将是错误的。
你需要做的是将laravel中的值绑定到vuejs可以使用的变量,类似这样的
Laravel blade
<script>
// this must be a json value
window.districts = {{$districts}}
</script>
在您的VueJS代码中,您需要将此值绑定到数据数组,然后才能使用它