首页 > 解决方案 > 无法从 [object object] 查询Selector:VueJS

问题描述

我想使用谷歌图表,我想查询选择器里面的一些元素,它返回 null

<template>
  <div class="pa-4">
    <GChart
      ref="gChart"
      :settings="{ packages: ['timeline'], state: timeRange }"
      type="Timeline"
      :data="chartData"
      :options="chartOptions"
      class="googleChart"
    />
  </div>
</template>

在脚本中:

  mounted() {
    this.nowLine()
  },
  methods: {
    nowLine() {
      const gchartQuery = document.querySelector('.googleChart')
      console.log(gchartQuery)
      console.log(this.$refs.gChart.$el)
    },
  },

当控制台日志返回时

<div state="[object object]" class="googleChart">...</div>

如果我使用此代码:

const gchartQuery = document.querySelector('.googleChart rect')
console.log(gchartQuery)

它返回 null 我无法查询其中的更多元素。

标签: javascriptvuejs2

解决方案


推荐阅读