我正在try 在Laravel中实现此Vue Word Cloud组件的TE自定义呈现器: https://github.com/SeregPie/VueWordCloud个
我首先使用php准备我的单词数组(正在工作):
@php
$tags = App\Models\Tag::withCount('songs')->orderBy("songs_count", "desc")->take(50)->get();
$words = "";
foreach($tags as $tag)
{
$count = $tag->countSongs();
$words .= "['$tag->name', $count],";
}
@endphp
然后我加上了云这个词(这是有效的)
<vue-word-cloud
style="
height: 480px;
width: 80%;
margin: 0 auto;
"
:words="[{{ $words }}]"
:color="([, weight]) => weight > 40 ? 'Red' : weight > 30 ? 'Orange' : weight > 20 ? 'Seagreen' : weight > 10 ? 'White' : weight > 5 ? 'LightSkyBlue ' : 'White'"
font-family="Nunito"
>
</vue-word-cloud>
但是当我try 像这样使用自定义渲染器时:(我需要这个来在每个单词周围加上一个链接)
<vue-word-cloud
style="
height: 480px;
width: 80%;
margin: 0 auto;
"
:words="[{{ $words }}]"
:color="([, weight]) => weight > 40 ? 'Red' : weight > 30 ? 'Orange' : weight > 20 ? 'Seagreen' : weight > 10 ? 'White' : weight > 5 ? 'LightSkyBlue ' : 'White'"
font-family="Nunito"
>
<template slot-scope="{text, weight, word}">
<div>
@{{ text }} <!-- this is not working, I need a link around the word here -->
</div>
</template>
</vue-word-cloud>
它会产生以下错误:
[Vue warn]: Property "text" was accessed during render but is not defined on instance.
我绝对不是VUE.js专家,也许我错过了一些微不足道的东西. 如何访问自定义呈现器的"Word"变量