Vueify 的组件模型为空

Component model from Vueify is empty

我刚刚开始使用 Vue.js,这是我第一次尝试使用 Vueify 和 Browserify。 我制作了这个简单的组件以从 Json 生成 table,但是我的组件应该显示的 div 是空的,我没有收到任何错误和 Vue 开发工具扩展显示我的 Json 所有正确的数据。我可能在这里做了一些非常愚蠢的事情,但我看不到它...

我的index.html:

<div class="content">
        <div id="vuePersonagens"></div>
        <script src="<?php echo get_stylesheet_directory_uri(); ?>/js/components/Personagens/build.js"></script>
</div>

Personagens.vue :

<template>
<div>
  <h1>Personagens</h1>
  <table v-for="personagem in personagens" class="table table-striped table-hover">
    <thead>
      <th>Nome</th>
      <th>Raça</th>
      <th>Classe</th>
      <th>Level Efetivo</th>
    </thead>
    <tbody>
      <tr>
          <td>{{ personagem.nome }}</td>
          <td>{{ personagem.raca }}</td>
          <td>{{ personagem.classe }}</td>
          <td>{{ personagem.level }}</td>
      </tr>
    </tbody>
  </table>
</div>
</template>

<script lang="ts">
  import * as Vue from 'vue'
  import Component from 'vue-class-component'

  @Component({
      props: {
        personagens: [{ "nome": String, "raca": String, "classe": String, level: Number}]
      }
  })
  export default class Personagens extends Vue {
        personagens: [{ "nome": String, "raca": String, "classe": String, level: Number}]
  }
</script>

start.js:

var Vue = require('vue')
var Personagens = require('./Personagens.vue')

new Vue({
   el: '#vuePersonagens',
   data: {
     personagens: [{ "nome": "Banjo", "raca": "Lizarkin", "classe": "Bard/Cleric", level: 8}]
   }
})

package.json:

{
  "name": "cleave",
  "version": "1.0.0",
  "description": "JSON",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://hsaldanha@bitbucket.org/hsaldanha/cleave.git"
  },
  "author": "Heitor Saldanha",
  "license": "ISC",
  "homepage": "https://bitbucket.org/hsaldanha/cleave#readme",
  "dependencies": {
    "@types/es6-promise": "0.0.32",
    "vue": "^2.3.4",
    "vue-class-component": "^5.0.1"
  },
  "devDependencies": {
    "vueify": "^9.4.1"
  },
  "browser": {
    "vue": "vue/dist/vue.common.js"
  }
}

Console showing empty DIV

Vue devtools shows my Json

您需要在 start.js 文件中注册 Personagens.vue 组件。

您可以在全局范围内执行此操作:

Vue.component('personagens', Personagens);

或在根组件中:

new Vue({
  el: '#vuePersonagens',
  components: { personagens: Personagens },
  data: {
    ...
  }
})

然后,您还需要在模板中实际包含组件的标签:

<div id="vuePersonagens">
  <personagens :personagens="personagens"></personagens>
</div>