我正在使用 vuex 和firebase按照vuegram的说明实现用户身份验证。我尝试了很多方法来分离 firebase 侦听器,唯一停止警告错误的方法如下:
var unsubscribe=fb.auth.onAuthStateChanged(user=>{
if(user){
store.commit('setCurrentUser',user)
store.dispatch('fetchUserProfile')
fb.usersCollection.doc(user.uid).onSnapshot(doc => {
store.commit('setUserProfile', doc.data())
})
}
})
unsubscribe();
Run Code Online (Sandbox Code Playgroud)
但是,上面的代码只是停止对 signOut() 发出警告,我无法再更新数据。
我的 store.js 文件:
var unsubscribe=fb.auth.onAuthStateChanged(user=>{
if(user){
store.commit('setCurrentUser',user)
store.dispatch('fetchUserProfile')
fb.usersCollection.doc(user.uid).onSnapshot(doc => {
store.commit('setUserProfile', doc.data())
})
}
})
export const store=new Vuex.Store({
state:{
currentUser:null,
userProfile:{}
},
actions:{
clearData({commit}){
commit('setCurrentUser',null)
commit('setUserProfile', {})
},
fetchUserProfile({ commit, state }) {
fb.usersCollection.doc(state.currentUser.uid).get().then(res => {
commit('setUserProfile', res.data())
}).catch(err => {
console.log(err)
})
},
updateProfile({ commit, state }, data) {
let displayName …Run Code Online (Sandbox Code Playgroud) 我有一个使用 vuex 存储用户访问过的帖子数据的博客应用程序,这样如果他们再次访问同一个帖子,他们就不需要再次从服务器获取数据。
将所有这些帖子数据存储在 vuex 中是个好主意吗?
它会减慢应用程序吗?
这种方法是否存在内存泄漏问题?
<div v-for="(n, index) in items" :id="n" @click="myMethod($event)">{{n}}</div>
Run Code Online (Sandbox Code Playgroud)
数组就像
items: [mouse, bull, tiger, rabbit, pig, cat, dog, horse]
Run Code Online (Sandbox Code Playgroud)
方法就像
myMethod: function(event){
console.log(event.target.id);
}
Run Code Online (Sandbox Code Playgroud)
我想单击每个 div,该 div 会告诉我其内容,因此我将内容绑定到每个 div 的 id。问题是我无法访问 中项目的索引myMethod()。我想将每个项目的索引用于其他目的。我怎样才能访问它们?目前我只能通过 id 属性将数据传递给方法。
我的资产文件夹中有 100 张名为 1.png 到 100.png 的图像。我想使用 v-for 显示它们,但我不想为它们硬编码每个 url。
<div v-for="n in 100">
<img src="../assets/photos/(1.png, 2.png...).png">
</div>
Run Code Online (Sandbox Code Playgroud)
我应该为 (1.png, 2.png...) 做什么?我应该使用将它们放入数据中吗?
我浏览了Nuxt的文档,但是找不到有关如何在新标签页中打开页面的信息。有没有办法在新标签页中打开链接,而不是在当前标签页中打开链接?我尝试了以下代码:
<nuxt-link to="/user" target="_blank">User</nuxt-link>
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。