gpt4 book ai didi

javascript - vue js布局中的组件不正确

转载 作者:行者123 更新时间:2023-12-03 02:36:00 25 4
gpt4 key购买 nike

我正在尝试使用 vuetify 实现一个支持布局的 Vue 应用程序。 Vue 新手,所以很可能会犯一些菜鸟错误。我的应用程序结构如下:
ma​​in.js

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuetify from 'vuetify'
import { App } from './app'
import router from './router'
import store from './store'
import('../node_modules/vuetify/dist/vuetify.min.css')

/* eslint-disable no-new */

console.log(router)

Vue.use(Vuetify)

new Vue({
el: '#app',
store,
router,
render: h => h(App)
})

路由器/index.js

import Vue from 'vue'
import Router from 'vue-router'
import routes from '../app/routes'

Vue.use(Router)

export default new Router({
mode: 'history',
routes: routes
})

app/index.js

export { default as routes } from './routes'
export { default as vuex } from './vuex'
export { default as App } from './App'

app/App.vue

<template>
<app-base-layout>
<v-content slot="content">
<v-container fluid="" fill-height="">
<v-layout justify-center="" align-center="">
<v-tooltip right="">
<v-btn icon="" large="" :href="source" target="_blank" slot="activator">
<v-icon large="">code</v-icon>
</v-btn>
<span>Source</span>
</v-tooltip>
</v-layout>
</v-container>
</v-content>
</app-base-layout>
</template>

<script>
import AppBaseLayout from './AppBaseLayout'
export default {
components: {
AppBaseLayout
},
data: () => ({
}),
props: {
source: String
}
}
</script>

app/AppBaseLayout.vue(注意 <slot name="content"></slot> )

<template>
<v-app id="inspire" dark="">
<v-navigation-drawer
clipped=""
fixed=""
v-model="drawer"
app="">

<v-list dense="">

<v-list-tile :to="{path: '/', params: {id: 'test'}}">
<v-list-tile-action>
<v-icon>home</v-icon>
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title>Home</v-list-tile-title>
</v-list-tile-content>
</v-list-tile>

<v-list-tile :to="{name: 'accountsListView', params: {id: 'add'}}">
<v-list-tile-action>
<v-icon>dashboard</v-icon>
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title>Tester</v-list-tile-title>
</v-list-tile-content>
</v-list-tile>

<v-list-tile @click.stop="dialog = true">
<v-dialog v-model="dialog" max-width="290">
<v-card>
<v-card-title class="headline">Use Google's location service?</v-card-title>
<v-card-text>Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="green darken-1" flat="flat" @click.native="dialog = false">Disagree</v-btn>
<v-btn color="green darken-1" flat="flat" @click.native="dialog = false">Agree</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-list-tile-action>
<v-icon>settings</v-icon>
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title>Settings</v-list-tile-title>
</v-list-tile-content>
</v-list-tile>
</v-list>
</v-navigation-drawer>
<v-toolbar app="" fixed="" clipped-left="">
<v-toolbar-side-icon @click.stop="drawer = !drawer"></v-toolbar-side-icon>
<v-toolbar-title>Lost Memories</v-toolbar-title>
</v-toolbar>

<slot name="content"></slot>

<v-footer app="" fixed="">
<span>&copy; 2018</span>
</v-footer>
</v-app>
</template>

<script>
export default {
data: () => ({
drawer: null,
dialog: false
}),
props: {
source: String
}
}
</script>

app/accounts/routes.js

import * as components from './components'

export default [
{
path: '/accounts',
component: components.AccountsListView,
name: 'accountsListView'
},
{
path: '/accounts/create',
component: components.CreateEditAccounts,
name: 'createAccounts'
},
{
path: '/accounts/edit',
component: components.CreateEditAccounts,
name: 'editAccounts'
}
]

我的app/accounts/components/AccountsListView.vueApp.vue完全相同,除了跨度工具提示中的文本不同(我尝试过更激进的可见性也会发生变化)。
疑问/问题:

  1. 为什么在访问 /accounts 时未显示 AccountsListView.vue,而我看到 App.vue
  2. 我重用布局组件的方法是否正确,或者我是否在重新发明轮子并且还有其他“正确”的方法?

最佳答案

A1。

检查您的components.AccountsListViewapp/accounts/routes.js
是否为空。当路由的组件为 null 时,Vue 不会抛出错误。如果有效,请检查您的 App.vue<router-view />或不。

A2。

我认为通过提供内容槽来重用布局是有效的。但我会直接在 App.vue 中定义布局并使用<router-view /><slot /> 。然后在 routes ,我将定义一个{ path: '/', component: Base }{ path: '/', component: Welcome } .

关于javascript - vue js布局中的组件不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48533584/

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