我已将manifest.json文件添加到我的Vue应用程序中。该文件位于一个名为scripts的文件夹中,然后在我的main.js中进行引用。但是,它实际上没有任何作用。例如,我将其设置为将显示设置为独立显示,将方向固定为纵向,并在用户将其添加到浏览器中的书签时添加标题和书签图标。不幸的是,由于某种原因,它似乎根本不起作用。我在哪里弄错了?
manifest.json如下
{
"name": "Bake Bread App",
"short_name": "Breadr",
"theme_color": "blue",
"background_color": "blue",
"display": "standalone",
"orientation": "portrait",
"Scope": "/",
"start_url": "/",
"icons": [
{
"src": "/assets/bookmark-icons/icon-72x72.png",
"sizes": "72x72",
"type": "image/png"
},
{
"src": "/assets/bookmark-icons/icon-96x96.png",
"sizes": "96x96",
"type": "image/png"
},
{
"src": "/assets/bookmark-icons/icon-128x128.png",
"sizes": "128x128",
"type": "image/png"
},
{
"src": "/assets/bookmark-icons/icon-144x144.png",
"sizes": "144x144",
"type": "image/png"
},
{
"src": "/assets/bookmark-icons/icon-152x152.png",
"sizes": "152x152",
"type": "image/png"
},
{
"src": "/assets/bookmark-icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/assets/bookmark-icons/icon-384x384.png",
"sizes": "384x384",
"type": "image/png"
},
{
"src": "/assets/bookmark-icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"splash_pages": null
}
然后,如果我们上一个级别(不在此scripts文件夹中)并进入main.js,我就有
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
Vue.config.productionTip = false;
// FILTERS
Vue.filter('snippet', function(value) {
return value.slice(0,100);
});
Vue.component('loading-screen', {
template: '<div id="loading">Loading...</div>'
});
import json from './scripts/manifest.json'
export default{
data(){
return{
myJson: json
}
}
}
new Vue({
router,
store,
render: h => h(App),
}).$mount("#app");
此外,我按照Google Developers Documentation的指示在自己的index.html中添加了<link rel="manifest" href="js/manifest.json">
。
答案 0 :(得分:0)
它无法在img
中用src
定义的Vue Data object
require()
版本中起作用的原因
和webpack需要了解图像。
您可以修改清单并为资源使用getter函数。
use require("path to the resource (not the manifest string)")
。helloWorld.vue:
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<ol v-for="x in myJson.icons" :v-bind="x" :key="x">
<li>
<div> name: {{x.name}}</div>
<div> name: {{x.sizes}}</div>
<div> name: {{x.type}}</div>
<img :src="getSrc(x.src)" alt="wrong..">
</li>
</ol>
</div>
</template>
<script>
import json from "../../manifest.json";
export default {
name: "HelloWorld",
data() {
return {
myJson: json,
msg: "Manifest:"
};
},
methods: {
getSrc(src) {
return require("../assets/" + src);
}
}
};
</script>
修改后的图标json:
"icons": [
{
"name": "logo",
"src": "logo.png",
"sizes": "99x99",
"type": "image/png"
},
{
"name": "logo2",
"src": "logo.png",
"sizes": "929x929",
"type": "image/png"
}
],