我正在使用 Vue 2.6.9 和新的 v-slot 语法。我想访问与插槽内的 v-model 交互。问题在于,在槽内显示数据可以,但使用 v-model 则不行。这是我的代码:
Vue.component('base-test', {
template: `
<div>
<slot :foo="foo" :foo2="foo2"></slot>
</div>
`,
data(){
return{
foo: 'Bar',
foo2: 'Bar 2'
}
}
});
// Mount
new Vue({
el: '#app'
});
<div id="app">
<base-test v-slot="sp">
<div>foo2 is {{ sp.foo2 }}</div>
<input type="text" v-model="sp.foo">
<div>foo is {{ sp.foo }}</div>
</base-test>
</div>
Run Code Online (Sandbox Code Playgroud)
我的问题是如何与插槽内的组件数据进行交互。
我正在使用缓存存储来构建渐进式Web应用程序(PWA).我需要将一个自定义对象放入缓存中,但缓存接受Response对象作为参数.所以我的问题是如何正确创建具有JSON的Response对象.我知道我可以使用其他缓存策略(localStorage或IndexedDB),但我对这种情况特别好奇 - 将缓存中的自定义JSON保存为请求.
var myJSON = JSON.stringify({custom:"object"});
caches.open('cache-name').then(function (cache) {
var response = new Response(); //My JSON should go into this Response obj.
return cache.put('cache-name', response);
});
Run Code Online (Sandbox Code Playgroud)