这堆代码如何完整的运行,求指教

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="vue.js"></script>
    <script src="vuex.js"></script>
</head>
<body>
    <div id="app">
        <h2>列表查询</h2>
        <input type="text" v-model="id">
        <button @click="search">搜索</button>
        <p>搜索结果:{{ this.$store.getters.search }}</p>
        <ul>
            <li v-for="item in this.store.state.todos">{{ item }}</li>
        </ul>
    </div>
    <script>
        const store = new Vuex.Store({
            state:{
                todos:[
                    {id: 1, text:'列表1'},
                    {id: 2, text:'列表2'},
                    //此处可以添加更多数据...
                ],
                id:0
            },
            mutations:{
                search (state,id) {
                    state.id = id
                }
            },
            getters:{
                search:state => {
                    return state.todos.filter(todo => todo.id == state.id)
                }
            }
        })
        var vm = new Vue({
            el: '#app',
            data: { id: ''},
            store,
            methods:{
                search(){
                    this.$store.commit('search', this.id)
                }
            }
        })
    </script>
</body>
</html>

添加了vue.js文件后,vuex.js不知道是啥,没有添加。运行结果如下

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值