在模块模式下无法访问Nuxt.js + Vuex中的getter

时间:2020-01-25 12:36:08

标签: vuex nuxt.js

我在通用模式下使用nuxt.js和vuex。

我的store/index.js看起来像这样

export const state = () => ({})

export const mutations = {}

export const getters = {}

我有一个store/cart.js文件

export const state = () => ({
  cartOpen: false
})

export const getters = {
  cartOpen(state) {
    return state.cartOpen;
  }
}

在我的Header.vue中,我有这个

<script>
import { mapGetters } from "vuex";

export default {
  name: "Header",
  computed: mapGetters({
    cartOpen: "cart/cartOpen"
  })
};
</script>

我也尝试过

  computed: {
    ...mapGetters("cart", ["cartOpen"])
  }

但是在我的vue devtools中,计算出的属性显示为undefined

1 个答案:

答案 0 :(得分:0)

您可以尝试 store / cart.js

from urllib.request import urlopen
from bs4 import BeautifulSoup
import requests as rq

listimg = [] # all images
for page in range(2,4):
    baseUrl = 'https://onepiecetreasurecruise.fr/Artwork/index.php?page=index'
    plusUrl = baseUrl + str(page)
    html = urlopen(plusUrl).read()
    soup = BeautifulSoup(html, 'html.parser')
    img = soup.find_all(class_='card-img-top')        
    for i in img:
       listimg.append(i['src'])
n = 1
for index, img_link in enumerate(listimg):
    img_data = rq.get(img_link).content
    with open('./onepiece/' + str(index+1) + '.png', 'wb+') as f:
        f.write(img_data)
        n += 1

在header.vue文件中,定义

export const getters = {
   GetCartOpen: state=> state.cartOpen
}

export default{
  data() {
   return {
    cart:false 
  };

它对我有用,也许对您也有用。祝你好运

OR

this。$ store.getters ['cart / GetCartOpen'];