1. 1.引入Vue
    2. <script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
    3. <div id="app">
    4. <input type="text" v-model="keyword">
    5. <button @click="handleAdd">添加</button>
    6. <h4>历史记录</h4>
    7. <button v-for="item of historyWords.slice(0,4)">{{item}}</button>
    8. </div>
    9. <script>
    10. new Vue({
    11. el:"#app",
    12. data(){
    13. return{
    14. msg:"hello qor",
    15. keyword:"",
    16. /* historywords长度为8 */
    17. historyWords:["你的名字","王菲"]
    18. }
    19. },
    20. methods:{
    21. handleAdd(){
    22. {
    23. if(!this.historyWords.includes(this.keyword)){
    24. this.historyWords.unshift(this.keyword)
    25. }
    26. }
    27. }
    28. }
    29. })
    30. </script>