【问题标题】:Laravel 5.7 vueJS component is mounted but not in devtoolsLaravel 5.7 vueJS 组件已安装但未在 devtools 中
【发布时间】:2019-04-24 07:30:52
【问题描述】:

所以我一直在努力解决这个问题,基本上我让我的组件运行一个控制台日志代码,显示组件已安装。但它不在开发工具中。我已经检查了我在配置上的本地开发环境,它也在屏幕截图中显示我是。我还将组件放在我正在使其在开发工具中不可见的页面中。我也试过了

window.Vue.config.devtools = true;
window.Vue.config.debug = true;
window.Vue.config.silent = false;

但没有运气。知道为什么会这样吗?

编辑: 这是我的刀片代码:

@extends('templates.master')
    @section('content')
        <div id="app">
            <div class="container-fluid">
                <div class="animated fadeIn">
                    <div class="row">
                        <div class="col-lg-12 col-md-12 col-sm-12">
                            <div class="card">
                                <div class="card-header">
                                    <i class="fa fa-align-justify"></i> Create a data list group
                                    <a href="{{ route('datalist.index') }}" class="btn btn-danger float-right text-light"><b><i class="icon-arrow-left"></i></b></a>
                                </div>
                                <div class="card-body">
                                    <div class="row">
                                        <div class="col-sm-12 col-md-12 col-lg-12">
                                            <form method="POST" action="{{ route('datalist.store') }}">
                                                {{ csrf_field() }}
                                                <div class="form-group">
                                                    <label for="name">Name</label>
                                                    <input type="text" class="form-control" value="{{ old('name') }}" name="name" id="name" aria-describedby="name" placeholder="Enter List Name">
                                                </div>
                                                <div class="form-group">
                                                    <label for="data_list_group_id">Select a group this list belongs to</label>
                                                    <select name="data_list_group_id" class="form-control" id="data_list_group_id" required>
                                                        @foreach($groups as $group)
                                                            <option value="{{ $group->id }}">{{ $group->name }}</option>
                                                        @endforeach
                                                    </select>
                                                </div>
                                                <label>Addional Columns</label>
                                                <datalist-column></datalist-column>
                                                @include('snippets.dialogs')
                                                <button type="submit" class="btn btn-primary float-right">Create</button>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    @endsection
    @section('additionalJS')
        <script src="{{ mix('js/app.js') }}"></script>
    @endsection

这是我的组件代码:

<template>
    <div>
        <div class="input-group mb-3" v-for="(column, index) in columns">
            <input type="text" class="form-control" placeholder="Column name" aria-label="Column name" aria-describedby="Column name">
            <div class="input-group-append" v-if="(index + 1) == columns.length">
                <button class="btn btn-primary" type="button" :id="index" @click="alert('HERE')">Add Column</button>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        data(){
            return {
                columns: [''],
            }
        },
        mounted(){
            console.log('Component mounted.');
            this.appendColumn('HERE');
        },
        updated: function () {
        },
        computed: {},
        watch: {},
        methods: {
            appendColumn(name){
                console.log("HERE");
                var app = this;
                app.columns.push(name);
            }
        },
        components: {}
    }
</script>

这是我的 app.js 代码:

/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

window.Vue = require('vue');
window.Vue.config.devtools = true;
window.Vue.config.debug = true;
window.Vue.config.silent = false;
/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */
Vue.component('datalist-column', require('./components/DataList/DataListColumn.vue'));

const app = new Vue({
    el: '#app'
});

我正在尝试让它变成这样:

【问题讨论】:

  • 请附上您的代码。您是否编写过任何数据对象或计算属性?正如它清楚地表明这个实例没有反应状态。
  • 我现在已经编辑了它现在包含的问题
  • 所以你的问题的答案是否定的,你没有写任何反应数据。
  • 这是什么意思?对不起,我是菜鸟。我的 .vue 组件上有它。
  • 它在我的 Vue.component('datalist-column', require('./components/DataList/DataListColumn.vue')); @迈克罗德姆

标签: laravel vue.js


【解决方案1】:

你没有反应状态意味着你没有指定一个。您可以像这样指定一个。

const app = new Vue({
    el: '#app',
    data() {
        return {
            message: 'hello, world!'
        }
    }
});

你会发现所有这些很棒的东西以及更多正确的东西here on the documentation

【讨论】:

  • 我的 .vue 组件中有 export default { data(){ return { columns: [''], } },mounted(){ console.log('Componentmounted.'); this.appendColumn('这里'); },更新:函数(){},计算:{},观看:{},方法:{ appendColumn(name){ console.log("HERE"); var 应用程序 = 这个; app.columns.push(name); } },组件:{} }
  • 但是您正在查看不包含任何数据的根目录。
  • 是的,这就是问题所在。根目录没有数据,只有在 devtools 中找不到的组件。
猜你喜欢
  • 2019-04-11
  • 2019-05-22
  • 2019-08-22
  • 2019-02-11
  • 1970-01-01
  • 1970-01-01
  • 2019-04-03
  • 2019-08-30
  • 2021-04-11
相关资源
最近更新 更多