小编fid*_*ido的帖子

vue.js select2多选

很多天我一直在寻找这个错误的答案.我尝试了很多替代品但没有任何效果

我需要选择多个值.当我选择多个值时,我的代码会挂起,但是当我使用单个选择时,它可以正常使用self.$emit('input', this.value).我需要的是选择多个值.

Select2.vue

<template>
    <select multiple class="input-sm" :name="name">
        <slot></slot>
    </select>
</template>
<style src="select2/dist/css/select2.min.css"></style>
<style src="select2-bootstrap-theme/dist/select2-bootstrap.min.css"></style>

<script>
    import Select2 from 'select2';

    export default{
        twoWay: true,
        priority: 1000,
        props: ['options', 'value', 'name'],
        data(){
            return{
                msg: 'hello'
            }
        },
        mounted(){
            var self = this;
            $(this.$el)
                .select2({theme: "bootstrap", data: this.options})
                .val(this.value)
                .trigger('change')
                .on('change', function () {
                    //self.$emit('input', this.value) //single select worked good
                    self.$emit('input',  $(this).val()) // multiple select
                })
        },
        watch: {
            value: function (value) {
                $(this.$el).val(value).trigger('change');
            },
            options: function (options) { …
Run Code Online (Sandbox Code Playgroud)

vue.js vue-component vuejs2

3
推荐指数
1
解决办法
5723
查看次数

Laravel 多对多关系:违反完整性约束

我有一个多对多的关系:

table 1 books  
table 2 authors  
table 3 books_authors  
        book_id, author_id
Run Code Online (Sandbox Code Playgroud)

问题是插入新记录时,出现此错误:

SQLSTATE [23000]:完整性约束违规:1048列'book_id'不能为空(SQL:INSERT INTO books_authors_relationshipauthor_idbook_idcreated_atupdated_at)的值(3,2015年12月10日17时17分二十八秒,2015年12月10日17: 17:28))

作者模型

class Author extends Model
{
   public function Book(){
      return $this->belongsToMany('App\Book','books_authors_relationship','book_id','author_id')->withTimestamps();
   }
}
Run Code Online (Sandbox Code Playgroud)

书型

   class Book extends Model
    {
    public function section(){
        return $this->belongsTo('App\Section','id');
    }

        public function author(){
            return $this->belongsToMany('App\Author','books_authors_relationship','book_id','author_id')->withTimestamps();
        }
    }
Run Code Online (Sandbox Code Playgroud)

图书控制器

 public function create($id)
        {
            $authors = Author::lists('first_name','id');
            $section_id = Section::find($id);
            return view('books.create_book',compact('section_id','authors'));

        }
     public function store(storeBookRequest $request)
        {
           // dd($request->input('authors')); …
Run Code Online (Sandbox Code Playgroud)

mysql laravel

1
推荐指数
1
解决办法
1420
查看次数

vue.js多选错误

问题与vue.js多选择我尝试了很多解决方案,但我没有找到解决方案,我得到错误[Vue警告]:期望一个数组值的绑定,但得到字符串

     <select name="users_id[]" multiple class="form-control" v-model="model.users_id" >
         <option>Select</option>
         <option v-for="users in option.users"
         v-bind:value="users.id">
         {{users.name}}
        </option>[![enter image description here][1]][1]
        </select>
 <script>   
    export default {
            props: ['title'],
            data(){
                return {
                   model: {
                        'title': '',
                        'users_id': '',
                    },
                    option: {
                        users: []
                    },
                }
            },
            created(){
                this.fetchData();
            },
            methods: {
                fetchData() {
                    let vm = this;
                    axios.get('/subject/create')
                        .then(function(response) {
                            Vue.set(vm.$data, 'option',   response.data.option)
                        })
                        .catch(function(error) {
                            console.log(error)
                        })
                },
</script>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

vue.js vuejs2

0
推荐指数
1
解决办法
3289
查看次数

标签 统计

vue.js ×2

vuejs2 ×2

laravel ×1

mysql ×1

vue-component ×1