gpt4 book ai didi

javascript - 为什么 vue js 在我的 laravel 项目中不起作用

转载 作者:行者123 更新时间:2023-12-01 00:23:38 25 4
gpt4 key购买 nike

我有一个 Laravel 项目,其中包含一些自定义更改我尝试过使用 Vue js 代码,但在我的情况下不起作用我已经运行了所有必需的命令,但当我检查控制台时仍然无法工作,它说消息未定义。

我的 webpack.config.js

 const mix = require('laravel-mix');

/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/

mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');

我的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');

import Vue from "vue";
//import Vue from 'vue/dist/vue.js';


// const files = require.context('./', true, /\.vue$/i);
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));


const app = new Vue({
el: '#app',
data:{
message: '',

},
methods: {
send()
{
console.log(this.message);
}
}
//
});

我的布局/app.blade.php

<!DOCTYPE html>
<html>
<head>
<title>Demo Laravel Vue Chat</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<!-- CSS Tags -->
<link rel="stylesheet" type="text/css" href="{{ asset('css/app.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('css/style.css') }}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Raleway:400,500,500i,700,800i" rel="stylesheet">
</head>
<body>
@include('partials.__nav')

<div class="container-fluid">
@yield('content')
</div>

@include('partials.__footer')


<!-- JS Tags -->
<script type="text/javascript" src="{{ asset('js/app.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/script.js') }}"></script>
</body>
</html>

我的索引文件,我使用在 app.js (#app) 中声明的 id

@extends('layouts.app')
@section('content')

<div class="row my-lg-2" id="app">
<div class="messaging">
<div class="inbox_msg">
<div class="inbox_people">
<div class="headind_srch">
<div class="recent_heading">
<h4>My Messages <span class="text-danger">(5 New)</span></h4>
</div>
<div class="srch_bar">
<div class="stylish-input-group">
<input type="text" class="search-bar" placeholder="Search Groups or Users" >
<span class="input-group-addon">
<button type="button"> <i class="fa fa-search" aria-hidden="true"></i> </button>
</span> </div>
</div>
</div>
<div class="inbox_chat">
<div class="chat_list active_chat">
<div class="chat_people">
<div class="chat_img"> <img src="{{ asset('img/todd.png') }}" alt="sunil"> </div>
<div class="chat_ib">
<h5>Todd Ogryzlo<span class="chat_date">Dec 25</span></h5>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</p>
</div>
</div>
</div>
<div class="chat_list">
<div class="chat_people">
<div class="chat_img"> <img src="{{ asset('img/bipin.png') }}" alt="sunil"> </div>
<div class="chat_ib">
<h5>Nepali Developers<span class="chat_date">Dec 25</span></h5>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</p>
</div>
</div>
</div>
<div class="chat_list">
<div class="chat_people">
<div class="chat_img"> <img src="{{ asset('img/victor.jpeg') }}" alt="sunil"> </div>
<div class="chat_ib">
<h5>Victor<span class="chat_date">Dec 25</span></h5>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</p>
</div>
</div>
</div>
<div class="chat_list">
<div class="chat_people">
<div class="chat_img"> <img src="{{ asset('img/kostas.png') }}" alt="sunil"> </div>
<div class="chat_ib">
<h5>Laravel PHP Canada<span class="chat_date">Dec 25</span></h5>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</p>
</div>
</div>
</div>
<div class="chat_list">
<div class="chat_people">
<div class="chat_img"> <img src="{{ asset('img/pratima.jpeg') }}" alt="sunil"> </div>
<div class="chat_ib">
<h5>Pratima Sharma<span class="chat_date">Dec 25</span></h5>
<p>Test, which is a new approach to have all solutions
astrology under one roof.</p>
</div>
</div>
</div>
<div class="chat_list">
<div class="chat_people">
<div class="chat_img"> <img src="{{ asset('img/nishal.jpeg') }}" alt="sunil"> </div>
<div class="chat_ib">
<h5>Nishal Gurung<span class="chat_date">Dec 25</span></h5>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</p>
</div>
</div>
</div>
<div class="chat_list">
<div class="chat_people">
<div class="chat_img"> <img src="{{ asset('img/niraj.jpeg') }}" alt="sunil"> </div>
<div class="chat_ib">
<h5>Niraj Pun Magar<span class="chat_date">Dec 25</span></h5>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</p>
</div>
</div>
</div>
</div>
</div>
<div class="mesgs">
<h3 class="first_head">Todd</h3>
<div class="msg_history">
<div class="incoming_msg">
<div class="incoming_msg_img"> <img src="{{ asset('img/todd.png') }}" alt="sunil"> </div>
<div class="received_msg">
<div class="received_withd_msg">
<p>Hi Bipin How Are you doing ?</p>
<span class="time_date"> 11:01 AM | June 9</span></div>
</div>
</div>
<div class="outgoing_msg">
<div class="sent_msg">
<p>I am Good Todd . What about you</p>
<span class="time_date"> 11:01 AM | June 9</span> </div>
</div>
<div class="incoming_msg">
<div class="incoming_msg_img"> <img src="{{ asset('img/todd.png') }}" alt="sunil"> </div>
<div class="received_msg">
<div class="received_withd_msg">
<p>How is newgrad project going ?</p>
<span class="time_date"> 11:01 AM | Yesterday</span></div>
</div>
</div>
<div class="outgoing_msg">
<div class="sent_msg">
<p>Going very good . Going to Finish it very soon</p>
<span class="time_date"> 11:01 AM | Today</span> </div>
</div>
<div class="incoming_msg">
<div class="incoming_msg_img"> <img src="{{ asset('img/todd.png') }}" alt="sunil"> </div>
<div class="received_msg">
<div class="received_withd_msg">
<p>Okkay Good ! When you finish let me and victor know about it</p>
<span class="time_date"> 11:01 AM | Today</span></div>
</div>
</div>
</div>
<div class="type_msg">
<div class="input_msg_write" id="app">
<input type="text" class="write_msg" placeholder="Type a message" v-model='message' />
<button class="msg_send_btn" type="button"><i class="fa fa-paper-plane-o" aria-hidden="true"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection

并且我在一次输入的索引文件底部使用了 v-model但它在控制台中显示错误并且都不显示索引页内容这是我在控制台中收到的错误

app.js:1 ReferenceError: message is not defined
at hn.eval (eval at Sa (app.js:1), <anonymous>:1:424)
at hn.e._render (app.js:1)
at hn.r (app.js:1)
at Nt.get (app.js:1)
at new Nt (app.js:1)
at app.js:1
at hn.$mount (app.js:1)
at hn.$mount (app.js:1)
at hn.e._init (app.js:1)
at new hn (app.js:1)
qe @ app.js:1
script.js:24 Uncaught TypeError: Cannot set property 'onclick' of null
at script.js:24

最佳答案

您应该 1) 从错误开始:

app.js:1 ReferenceError: message is not defined
at hn.eval (eval at Sa (app.js:1), <anonymous>:1:424)
at hn.e._render (app.js:1)
at hn.r (app.js:1)
at Nt.get (app.js:1)
...

然后 2) 向后进行:

require('./bootstrap');

window.Vue = require('vue');

import Vue from "vue";
//import Vue from 'vue/dist/vue.js';

// const files = require.context('./', true, /\.vue$/i);
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));

const app = new Vue({
el: '#app',
data: {
message: '',
},
methods: {
send() {
console.log(this.message); // <-- Do you have a "this.message" in app?
}
}
});

所以也许解决方案是 console.log(this.data.message); 请尝试一下,然后发回您发现的内容。

更重要的是,请熟悉JS调试工具,例如Visual Studio Code和/或 Chrome Developer Tools .

关于javascript - 为什么 vue js 在我的 laravel 项目中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59198812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com