我刚刚开始使用 Vue.js,这是我第一次尝试使用 Vueify 和 Browserify。我制作了这个简单的组件来从 Json 生成一个表格,但是我的组件应该显示的 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>
人物角色.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>
开始.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}]
}
})
包.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"
}
}