npm运行手表构建成功并且laravel混合,但是在浏览器上无法访问ERR_CONNECTION_REFUSED

时间:2019-09-13 15:59:47

标签: laravel notifications

当我尝试使用pusher在laravel实时应用程序上运行时:

npm run watch 

编译成功,laravel混合成功建立,但是当我打开浏览器并尝试访问url时

http://localhost:8000
or 
http://localhost:8001
or
http://localhost:8079
or
http://localhost:8080

我在浏览器上发现ERR_CONNECTION_REFUSED时浏览器上的所有此端口相同错误,但是我运行的服务器和mysql正确

但是我运行php artisan可以很好地运行应用程序

这是我的app.js

require('./bootstrap');

window.Vue = require('vue');

window._ = require('lodash');

window.$ = window.jQuery = require('jquery');


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

Vue.component('order', require('./components/orderNotification.vue'));
const app = new vue({

    el: '#app',

    data: {
        orders: '',
    },

    created() {
        if (window.Laravel.userId) {
            axios.post('/notification/order/notification').then(response => {
                this.orders = response.data;
                console.log(response.data)
            });

            Echo.private('App.user.' + window.Laravel.userId).notification((response) => {

                data = { "data": response };
                this.orders.push(data);
                console.log(response.data)

            });
        }
    }
});

和这个bootstrap.js

window._ = require('lodash');


/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 */

try {
    window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');

    require('bootstrap');
} catch (e) {}



window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';


let token = document.head.querySelector('meta[name="csrf-token"]');

if (token) {
    window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
    console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}


import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    encrypted: true
});

1 个答案:

答案 0 :(得分:0)

原因是因为您尚未启动Laravel开发服务器。运行php artisan serve命令以启动服务器并运行