Vue:来自一家酒店

时间:2018-04-21 02:01:53

标签: vue.js vue-router vuetify.js

我从我的数据中的数组创建了我的视图列表链接但是可以将:to property绑定到我的对象中的项目?东西链接这个

global $post, $wpdb;

$taxonomies = $wpdb->get_col( "SELECT DISTINCT tt.taxonomy
FROM {$wpdb->prefix}term_taxonomy as tt
JOIN {$wpdb->prefix}term_relationships as tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
WHERE tr.object_id = {$post->ID}" );

// Loop through all taxonomies for this WP_Post object
foreach ( $taxonomies as $taxonomy ) {
    // Get the WP_Term objects for this taxomnomy and this post ID
    $terms = wp_get_post_terms( $post->ID, $taxonomy );
    // If this taxonomy has terms for this post ID
    if( count($terms) > 0 ){
        $term_names = array();

        // Get the taxonomy label name
        $taxonomy_label_name = get_taxonomy( $taxonomy )->labels->name;
        $taxonomy_label_singular_name = get_taxonomy( $taxonomy )->labels->singular_name;

        // Loop through each WP_Term object for this taxomnomy and this post ID
        foreach ( $terms as $term ) {
            $term_id     = $term->term_id; // The term ID
            $term_slug   = $term->slug;  // The term slug
            $term_name   = $term->name;  // The term name
            $term_parent = $term->parent; // The term parent ID
            $description = $term->description; // The term description
            $term_link   = get_term_link( $term, $taxonomy ); // The term link

            // Set the term name in an array (for testing display)
            $term_names[] = $term_name;
        }
        // Output taxonomy label name with the coma separated terms
        echo '<p><strong>' . $taxonomy_label_name . ':</strong> ' . implode(', ', $term_names) . '</p>';
    }
}

2 个答案:

答案 0 :(得分:1)

v-bind中的任何内容都应该是有效的Javascript表达式

在这种情况下,它应该只是一个有效的Javascript对象

:to="{name: item.componentName}"

答案 1 :(得分:1)

您的问题是您在v-bind表达式中尝试变量插值({{item.componentName}}部分)。这不受支持。

相反,您可以使用任何有效的JavaScript表达式,它将自动检测组件级数据范围(即使在v-for循环中!)。例如,您想要的表达式应为:

:to="{name: item.componentName}"

v-for所述,以下玩具示例也有效:

<div v-for="(item, item_index) in itemsArray">
    <my-component :myProp="{name: item.componentName, position: item_index}"></my-component>
</div>

只有在尝试在v-binding之外渲染某些值时才需要插值,例如显示一些文字:

<div>{{item.componentName}}</div>