Vue 获取值问题

html:

<div id="page">
    <button v-for="list in lists" v-on:click="clickEvent">{{list.page}}</button>
</div>

js:

new Vue({
    el:'#page',
    data:{
        lists:[
            {page:1},
            {page:2},
            {page:3},
            {page:4}
        ]
    },
    methods:{
        clickEvent:function () {
            url = '<?php echo Yii::$app->urlManager->createUrl("/collect-data-copy/result")?>';
            console.log(this);
            $.post(url,{page:$(this).text()},function (data) {
                console(data);
            },'json');
        }
    }
});

现在想把被点击的button的值传给后台,应该怎么弄?page:$(this).text() 这个要如何该?

阅读 4.1k
2 个回答

传入到你的方法里面就行,
html:

v-on:click(item.text)

js:

function(text)

然后在传入post请求即可

page:text

手机上码的字,哈哈?

好歹已经用上vue了,把$这个东西干掉吧……
vue-resource挺好用的啊。

你这里的,这么改就行了:

<div id="page">
    <button v-for="list in lists" v-on:click="clickEvent($event.textContent)">{{list.page}}</button>
</div>
clickEvent:function (text) {
    url = '<?php echo Yii::$app->urlManager->createUrl("/collect-data-copy/result")?>';
    this.$http.post(url, text)
        .then((res) => {
            console(data);
        });
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题