GVKun编程网logo

使用 Vue.js 时如何关闭 Laravel 混合路由(vue关闭当前路由)

20

本篇文章给大家谈谈使用Vue.js时如何关闭Laravel混合路由,以及vue关闭当前路由的知识点,同时本文还将给你拓展javascript-laravel使用vue-resources报错Larav

本篇文章给大家谈谈使用 Vue.js 时如何关闭 Laravel 混合路由,以及vue关闭当前路由的知识点,同时本文还将给你拓展javascript - laravel使用vue-resources 报错 Laravel is not defined ?、javascript – 在Laravel 5.3中使用Vue.js.、javascript – 如何在laravel刀片中使用vue.js组件?、Laravel + VueJS应用程序Laravel Passport {“ message”:“未经身份验证”}问题等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

使用 Vue.js 时如何关闭 Laravel 混合路由(vue关闭当前路由)

使用 Vue.js 时如何关闭 Laravel 混合路由(vue关闭当前路由)

如何解决使用 Vue.js 时如何关闭 Laravel 混合路由?

我将 Vue.js 前端与 Laravel 混合使用。我正在使用 Vue 路由器进行路由,但问题是当页面刷新时,路由由 laravel 处理,并且显示“404 未找到”。所以我的问题是,如何关闭默认的 Laravel 路由或确保所有路由都由 vue 处理。如果这是一个愚蠢的问题,我很抱歉,我是初学者。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

javascript - laravel使用vue-resources 报错 Laravel is not defined ?

javascript - laravel使用vue-resources 报错 Laravel is not defined ?

laravel5.3 使用 vue-resoure 报错,
javascript - laravel使用vue-resources 报错 Laravel is not defined ?

javascript - laravel使用vue-resources 报错 Laravel is not defined ?
javascript - laravel使用vue-resources 报错 Laravel is not defined ?

回复内容:

laravel5.3 使用 vue-resoure 报错,
javascript - laravel使用vue-resources 报错 Laravel is not defined ?

javascript - laravel使用vue-resources 报错 Laravel is not defined ?
javascript - laravel使用vue-resources 报错 Laravel is not defined ?

javascript – 在Laravel 5.3中使用Vue.js.

javascript – 在Laravel 5.3中使用Vue.js.

在5.3之前的Laravel项目中,我使用脚本标记使用了Vue.js,如下所示:

<script type="text/javascript" src="../js/vue.js"></script>

然后我会创建一个特定于该页面的Vue实例,如下所示:

<script>
    new Vue({
      el: '#app',
      data: {
        message: 'Hello Vue.js!'
      }
    });
</script>

然后将其绑定到我的HTML中相关的div#id.

现在,在Laravel 5.3 Vue.js捆绑在一起,我完全清楚我可以使用gulp / elixir来使用文档中描述的组件,但是,我的问题是我是否想创建一个像我刚才提到的Vue.js实例,即我严格为给定页面(不是组件)创建Vue.js实例的地方我该怎么办?

我是否像以前一样通过在脚本标记中导入vue.js库来设置它,还是可以使用生成的app.js?

我不应该这样做,我应该为一切创建组件吗?

对我来说,为我只使用一次的东西制作一个组件是没有意义的 – 我认为组件的目的是它们可以重复使用 – 你可以在不止一个地方使用它.如Vue.js文档中所述:

Components are one of the most powerful features of Vue.js. They help you extend basic HTML elements to encapsulate reusable code.

任何建议将不胜感激,谢谢!

解决方法:

我会用Webpack离开Laravel.这使您能够添加一些良好的Webpack配置.此外,gulp手表现在可以在Homestead vagrant VM中运行,因为它将使用Webpack来监视文件更改.并查看异步组件.

现在回答你关于每页单独的Vue实例的问题……让我们从app.js开始……

App.js
首次安装Laravel 5.3时,您将找到app.js入口点.让我们注释掉主要的Vue实例:

资源/资产/ JS / app.js

/**
 * First we will load all of this project's JavaScript dependencies which
 * include Vue and Vue Resource. This gives a great starting point for
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

/**
 * 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('example', require('./components/Example.vue'));

// Let's comment this out, each page will be its own main Vue instance.
//
// const app = new Vue({
//     el: '#app'
// });

app.js文件仍然是全局内容的地方,因此这里添加的组件可用于包含它的任何页面脚本(例如上面看到的示例组件).

欢迎页面脚本
现在让我们创建一个代表欢迎页面的脚本:

资源/资产/ JS /页/ welcome.js

require('../app')
import Greeting from '../components/Greeting.vue' 

var app = new Vue({
    name: 'App',
    el: '#app',
    components: { Greeting },
    data: {
        test: 'This is from the welcome page component'
    }
})

博客页面脚本
现在让我们创建另一个代表博客页面的脚本:

资源/资产/ JS /页/ blog.js

require('../app')
import Greeting from '../components/Greeting.vue' 

var app = new Vue({
    name: 'App',
    el: '#app',
    components: { Greeting },
    data: {
        test: 'This is from the blog page component'
    }
})

问候组件
资源/资产/ JS /组件/ Greeting.vue

<template>
    <div>
       {{ message }}
    </div>
</template>

<script>
    export default {
        name: 'Greeting',
        data: () => {
            return {
                message: 'This is greeting component'
            }
        }
    }
</script>

欢迎Blade View
让我们更新Laravel附带的欢迎刀片视图:

<!DOCTYPE html>
<html lang="en">
    <head>
        <Meta charset="utf-8">
        <Meta http-equiv="X-UA-Compatible" content="IE=edge">
        <Meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel</title>
    </head>
    <body>
        <div id="app">
            <example></example>
            @{{ pageMessage }}
            <greeting></greeting>
        </div>

        <script src="/js/welcome.js"></script>
    </body>
</html>

博客视图的想法是一样的.


现在使用Elixir将Webpack配置选项与其自身合并的能力(在更多关于here的更多内容)中将所有内容整合到您的gulp文件中:

gulpfile.js

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

require('laravel-elixir-vue-2');

/*
 |--------------------------------------------------------------------------
 | Elixir Asset Management
 |--------------------------------------------------------------------------
 |
 | Elixir provides a clean, fluent API for defining some basic Gulp tasks
 | for your Laravel application. By default, we are compiling the Sass
 | file for our application, as well as publishing vendor resources.
 |
 */

elixir(mix => {
    var config =  elixir.webpack.mergeConfig({
          entry: {
            welcome: './resources/assets/js/pages/welcome.js',
            blog: './resources/assets/js/pages/blog.js'
          },
          output: {
            filename: '[name].js' // Template based on keys in entry above
          }
       });

    mix.sass('app.scss')
       .webpack('app.js', null, null, null, config);
});

运行gulp或gulp watch,你会看到welcome.js和blog.js都已发布.

思考
我目前正在使用SPA路线来谈谈“网络应用程序”,并且只使用Laravel作为后端API(或任何其他语言/框架).我已经看到一些Vue SPA在Laravel中构建的例子,但我认为它应该是一个完全独立的repo /项目,独立于后端. SPA中没有涉及Laravel / PHP模板视图,因此请单独构建SPA.顺便说一下,SPA会有“页面”组件(通常由VueRouter调用,当然也会由更多嵌套组件组成…请参阅下面的示例项目链接).

但是,对于“网站”,我认为Laravel仍然是提供刀片视图的不错选择,而且无需为此提供SPA.你可以做我在这个答案中描述的内容.此外,您可以将您的网站连接到您的网络应用程序.在您的网站上,您将拥有一个“登录”链接,该链接将用户从网站到webapp SPA进行登录.您的网站仍然是SEO友好的(虽然有很好的证据表明Google也在SPA javascript网站上看​​到内容).

为了了解SPA方法,我在Vue 2.0中提供了一个示例:https://github.com/prograhammer/example-vue-project(它运行良好,但仍在进行中).

编辑:

您可能还想检查Commons Chunk Plugin.这样浏览器可以分别缓存一些共享模块依赖项. Webpack可以自动提取共享的导入依赖项并将它们放在一个单独的文件中.这样你就可以在页面上同时拥有common.js(共享内容)和welcome.js.然后在另一个页面上,您将再次拥有common.js和blog.js,浏览器可以重用缓存的common.js.

javascript – 如何在laravel刀片中使用vue.js组件?

javascript – 如何在laravel刀片中使用vue.js组件?

我在我的app.js中注册了这样的组件:

Vue.component('navbar', require('./components/Navbar.vue'));

现在我要导入该组件:

<template>
<nav>CODE HERE</nav>
</template>

进入我的blade.PHP文件:

<body>
    <div id="app">
        <div>
        <navbar></navbar> <-- here!
        @yield('content')
        </div>
    </div>
</body>

最简单的方法是什么?

解决方法:

在app.js

import navbar from './components/Navbar.vue';
Vue.component('navbar', require('./components/Navbar.vue'));

var app = new Vue({
   el: '#app',
   components: {
       'navbar': require('./components/Navbar.vue'),
   }
});

在你的刀片中:

<body>
<div id="app">
    <div>
       <navbar></navbar>
       @yield('content')
    </div>
</div>

Laravel + VueJS应用程序Laravel Passport {“ message”:“未经身份验证”}问题

Laravel + VueJS应用程序Laravel Passport {“ message”:“未经身份验证”}问题

将带有Bearer [您的令牌]的Authorization标头添加到请求中,然后再次发送,然后检查它是否仍返回Unauthenticated。

今天关于使用 Vue.js 时如何关闭 Laravel 混合路由vue关闭当前路由的介绍到此结束,谢谢您的阅读,有关javascript - laravel使用vue-resources 报错 Laravel is not defined ?、javascript – 在Laravel 5.3中使用Vue.js.、javascript – 如何在laravel刀片中使用vue.js组件?、Laravel + VueJS应用程序Laravel Passport {“ message”:“未经身份验证”}问题等更多相关知识的信息可以在本站进行查询。

本文标签: