douhui8454 2018-09-18 23:53
浏览 174

Vue.js刷新页面时返回JSON

I am new to vue.js , and I am loving it already, except for the fact that I am stocked with an ugly part I don't like which is "page returns JSON when I hit on refresh"

page loads normaly On Refresh Page loads JSON

However if I go through the master page, i.e the main page it loads correctly as expected, but if I click on refresh I get a JSON response.

I am using laravel for my backend, in my controller, I am returning a JSON Response (yes I know), however, I am kind of expecting vue.js to auto-detect links for me and do its magic like it would if I go to the link/page from the master page.

Here is what the controller returning the item to the master page looks like

public function index()
{
    //
        $task = TodoTask::orderBy('created_at', 'desc')->paginate(4);
        return equest()->json(200, $task);

}

I have done quite a couple of research on this, and I got to understand from this link https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations that I have got to configure my .htaccess file to be able to do so.

Here is what my .htaccess file looks like

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

What might I possibly be doing wrong?

my vue routes

/**
 * 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 = require('vue');
import VueRouter from 'vue-router';

window.Vue.use(VueRouter);

Vue.component('example-component', require('./components/ExampleComponent.vue'));
//Vue.component('tasks', require('./components/TodoTask.vue'));
const example = require('./components/ExampleComponent.vue');
const Samplelink = require('./components/SampleComponent.vue');
const task = require('./components/TodoTask.vue');



const routes = [{
    path: '/example',
    component: example

}, {
    path: '/sample',
    component: Samplelink
}, {
    path: '/tasks',
    component: task
}];

const router = new VueRouter({
    mode: 'history',
    routes
});


const app = new Vue({
    el: '#app',
    router
}).$mount('#app');
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败