vue.js - Vue Apollo instance option issues, can't configure properly
问题描述
I'm working on integrating Vue-Apollo into a Laravel project right now. I was able to get Vue up and running just fine. Now I am trying to integrate Apollo and it isn't working. I feel like I'm missing something really simple but can't locate it.
Here's my App
component:
<template>
<div>
<slot></slot>
</div>
</template>
<script>
export default {
name: 'app',
}
</script>
my blade template:
@extends('layouts.app')
@section('content')
<div id="app">
<div class="container">
<div class="row justify-content-center">
<App>
<h1>Here</h1>
<manufacturers-component></manufacturers-component>
<product-groups-component></product-groups-component>
<products-component></products-component>
</App>
</div>
</div>
</div>
@endsection
Lastly, my JS where I instantiate my Vue:
require('./bootstrap');
import Vue from 'vue'
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import VueApollo from 'vue-apollo'
import App from './components/App'
Vue.component('manufacturers-component', require('./components/ManufacturersComponent.vue'));
Vue.component('product-groups-component', require('./components/ProductGroupsComponent.vue'));
Vue.component('products-component', require('./components/ProductsComponent.vue'));
const httpLink = new HttpLink({
uri: 'http://homestead.test/graphql'
})
const apolloClient = new ApolloClient({
link: httpLink,
cache: new InMemoryCache()
})
Vue.use(VueApollo)
const apolloProvider = new VueApollo({
defaultClient: apolloClient
})
const vue_app = new Vue({
el: '#app',
components: { App },
apolloClient,
render: h => h(App)
});
The thing is it does mount the App
component briefly, I see a flash of the h1 content reloading the page, but then goes blank. No errors pop up, I've stepped through the loading process and can't find anything sticking out as wrong. No errors are thrown either.
解决方案
安装后,刀片文件中的 HTML 将被替换为 App 组件的内容,因此出现简短的外观和随后的白页。将标记从刀片文件移动到您的 App 组件中:
应用程序.vue
<template>
<div class="container">
<div class="row justify-content-center">
<h1>Here</h1>
<manufacturers-component></manufacturers-component>
<product-groups-component></product-groups-component>
<products-component></products-component>
</div>
</div>
</template>
<script>
export default {
name: 'app',
}
</script>
index.blade.php
@extends('layouts.app')
@section('content')
<div id="app"></div>
@endsection
推荐阅读
- scikit-learn - 使用对数损失函数的 sklearn.linear_model.SGDClassifier 运行时间很长
- java - 如何使用 SpringBoot 从 cassandra 中检索空集
- ios - 打印到标签的距离
- javascript - React - 基于浏览器的差异加载(es5、es6、esnext 等)
- single-page-application - 适用于 PWA/SPA 的 Google Ads 解决方案?
- java - 如何修复 docker-compose 中 Jedis 中的连接被拒绝错误?
- vim - .vimrc 仅在 virtualenv 内导致错误
- android - Android recycleview 在数据更新时重复
- typescript - 如何在函数中返回获取结果
- git - 如何删除 Azure Git 推送历史记录?