我的vue-cli应用程序存在一些问题。
这个应用程序是使用webpack模板制作的。在我的App.vue上,我正在使用一个组件,其中图像加载正常,但对于视图路由器呈现的每个组件,尽管文件路径与Header.vue文件上使用的图像完全相同,但图像不显示。
我跑的时候:
npm run dev
我在Header.vue上引用的图像放在静态文件夹上工作正常,但这是唯一有效的图像。
index.html文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>bkchat_proto1</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.7/js/all.js"></script>
<link rel="stylesheet" href="https://use.typekit.net/mbh1drh.css">
<style>
body {
background-color:#D5DDE5;
}
.section {
background-color:#fff !important;
padding:0.5em;
border-radius: 4px;
margin-left: auto;
margin-right: auto;
width:100% !important;
}
.font1 {
font-family: "anzeigen-grotesk",sans-serif;
}
.font2 {
font-family: "prohibition",sans-serif;
}
.font3 {
font-family: "rift-soft";
}
.font4 {
font-family: "industry-inc-base";
}
.postImg {
background-size: contain;
background-repeat: no-repeat;
min-width:inherit;
height:15em;
}
@media (max-width: 992px) {
.postImg {
min-height:300px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
App.vue文件:
<template>
<div id="app" class="container">
<Header></Header>
<div class="row">
<router-view></router-view>
<Aside></Aside>
</div>
<Footer></Footer>
</div>
</template>
<script>
import Header from './components/Header';
import Footer from './components/Footer';
import Aside from './components/Aside';
export default {
name: 'app',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
},
components: {
'Header':Header,
'Aside':Aside,
'Footer':Footer
}
}
</script>
<style>
</style>
Header.vue文件:
<template lang="html">
<div>
<header class="header_img">
</header>
<nav>
<ul>
<li v-for="link in navLinks">
<a :href="link.url" class="font3"> {{link.name}}</a>
</li>
</ul>
</nav>
</div>
</template>
<script>
export default {
data(){
return {
navLinks:[
{
name:'home',
url:'/'
},
{
name:'contact',
url:'/contact'
},
{
name:'cast members',
url:'/cast_members'
}
]
}
}
}
</script>
<style lang="css" scoped>
.header_img {
background-image: url('../assets/img/header.jpg');
background-size:contain;
height:20em;
width:100%;
margin-left: auto;
margin-right: auto;
}
nav ul li {
list-style: none;
display:inline-block;
margin-left: 0.5em;
margin-right: 0.5em;
text-transform: uppercase;
}
nav ul {
text-align: center;
}
nav {
background-color:#0882FF;
width:90% !important;
margin-left: auto;
margin-right: auto;
box-shadow: 1px 2px 5px;
}
nav ul li a {
text-decoration:none;
color:white;
font-size: 1.5em;
text-shadow: 1px 2px 5px black
}
nav ul li a:hover {
color:#FFC611;
}
</style>
Footer.vue文件:
<template lang="html">
<footer class="row">
<div class="col-lg-12">
<h3 class="font2"><span>B</span><span class="flip">K</span>CHAT</h3>
</div>
</footer>
</template>
<script>
export default {
}
</script>
<style lang="css">
footer {
margin-top:3em;
background-color:#262624;
max-height:300px;
}
.flip {
transform:rotate(180deg);
-webkit-transform:rotate(180deg);
position:relative;
}
footer h3 {
color:white;
}
</style>
Aside.vue:
<template lang="html">
<div class="col-lg-4">
<aside class="section">
<label for="search" class="font2">SEARCH</label>
<input type="search" name="search" value="" placeholder="Look for something...">
<hr>
<div class="social_icons">
<h5 class="font2">{{social_msg}}</h5>
<i class="fab fa-facebook-f fa-2x"></i>
<i class="fab fa-twitter fa-2x"></i>
<i class="fab fa-instagram fa-2x"></i>
<i class="fab fa-snapchat-ghost fa-2x"></i>
<i class="fab fa-youtube fa-2x"></i>
</div>
</aside>
</div>
</template>
<script>
export default {
data(){
return {
social_media:[
{
name:'',
link:'',
icon:''
}
],
social_msg:'FOLLOW US'
}
}
}
</script>
<style lang="css">
svg {
display: block !important;
margin:1em auto 1em auto;
}
.social_icons {
padding:1em;
}
h5, svg{
text-align:center;
}
input[type="search"] {
border: 0px;
border-bottom: 2px solid grey;
margin-left:0.5em;
}
input[type="search"]:focus {
outline:none;
}
</style>
我遇到图像问题的文件:
Main.vue:
<template lang="html">
<section class="col-lg-8">
<div class="section">
<h1 class="font1">{{welcome_title}}</h1>
<p>{{welcome_msg}}</p>
<hr>
<h1 class="font2">{{news_title}}</h1>
<div class="news_post" v-for="news in news_post">
<div v-if="news.img !== '' " class="row">
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 col-xl-4">
<div class="postImg" v-bind:style="{'background-image': 'url('+ news.img +')'}"></div>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8 col-xl-8">
<h2 class="font1">{{news.title}}</h2>
<p class="content">{{news.content}}</p>
</div>
</div>
<div v-else class="row">
<div class="col-lg-12">
<h2 class="font1">{{news.title}}</h2>
<p class="content">{{news.content}}</p>
</div>
</div>
<hr>
</div> <!-- end of for -->
</div>
</section>
</template>
<script>
import Aside from './Aside';
export default {
data(){
return{
welcome_title:'Welcome to BkChat LDN!',
welcome_msg:'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
news_title:'NEWS',
news_post:[
{
title:'Latest news from BkChat:',
img:'',
content:'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.',
id:'1',
date:''
},
{
title:'Latest news from BkChat:',
img:'../assets/img/img1.jpg',
content:'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.',
id:'1',
date:''
},
{
title:'Latest news from BkChat:',
img:'',
content:'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.',
id:'1',
date:''
}
]
}
}// end of data
}
</script>
<style lang="css" scoped>
.content,.news_post {
margin:1em;
}
.news_post > .row > div > h2{
margin-left: 0.5em;
}
</style>
路由器/ index.js:
import Vue from 'vue'
import Router from 'vue-router'
import Contact from '../components/Contact.vue'
import Main from '../components/Main.vue'
import CastMembers from '../components/castMembers.vue'
Vue.use(Router)
export default new Router({
routes: [
{path:'/', component:Main},
{path:'/contact', component:Contact},
{path:'/cast_members', component:CastMembers}],
mode:'history'
})