Vue.js将数据传递到另一页

时间:2017-08-11 08:05:48

标签: javascript html vue.js vue-router

我使用vue-resource从REST API获取数据,并在着陆页中显示数据列表。用户会看到Title和简短描述,并且当Title用户的点击进入该页面时。当我使用a代码URL时,router-link工作正常,但在使用Title时,它不会显示<div class="food_list_content_bg" id="app-router"> <div class="food_list_content"> <h3><a href="">Article Name</a></h3> <router-link to="restaurant-profile.html"><h5>{{ rest.title.rendered }}</h5></router-link> <ul v-for="csn in rest.cuisine_type"> <li>{{ csn.name }}</li> </ul> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> </div> <div class="single_food_list_footer_top"> <a href=""> <ons-icon icon="fa-user" size="20px" fixed-width="false"> </ons-icon> </a> <div class="publisher-name"> <strong>Added By</strong> <p>Board Name</p> </div> </div> <div class="single_food_list_footer"> <p>Picked For</p> <strong>"ITEM"</strong> </div> </div>

HTML

(function($){
    var config = {
        api: {
            restaurants: 'data-url'
        },

    };

    var restaurants = new Vue( {
        el: '#post-list-tmpl',
        data: function() {
            return {
                restaurant: [],
                cuisin: []
            }
        },
        mounted: function () {
            this.getRestaurant();
        },
        methods: {
            getRestaurant: function () {
                var self = this;
                $.get( config.api.restaurants, function(r){
                    self.$set(self, 'restaurant', r);
                });
            }
        }
    });

    var router = new VueRouter({
        mode: 'history',
        routes: [
            { path: 'restaurent-profile.html', name: 'restaurent', component: restaurent },
        ]
    });

    new Vue({
        router,
    }).$mount('#app-router');

})( jQuery );

JS

id

此处JSFiddle。如何让它发挥作用??

另外,我需要将点击的项目的restaurant-profile.html传递到下一页Vue.js。有办法吗?

我直接使用script包含Vue.js。如果可能的话,我宁愿选择一种方法来安装func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) //Button_Action addSongButtonIdentifier(cell: cell, indexPath.row) }

0 个答案:

没有答案