vue的小练习-翻转单词

先将字符串转成数组,用reverse()翻转数组,再转成字符串

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
       <h2> {{string}}</h2>
        <button @click="reverse">逆转世界</button>

    </div>
    <script src="../../vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                string:'Hello,world',
            },
            methods:{
                reverse(){
                    //先将字符串转成数组,用reverse()翻转数组,再转成字符串
                    this.string=this.string.split('').reverse().join('')
                }
            }
        })
    </script>
</body>

</html>
相关推荐
洁洁!6 分钟前
数据采集助力AI大模型训练
前端·人工智能·easyui
MaCa .BaKa11 分钟前
25-智慧旅游系统(协同算法)三端
java·javascript·vue.js·spring boot·tomcat·maven·旅游
MiyueFE15 分钟前
bpmn-js 源码篇9:Moddle - 对象格式的标准化定义库
前端·javascript
excel21 分钟前
webpack 核心编译器 七 节
前端
Debug 熊猫28 分钟前
【Java基础】10章、单例模式、final关键字的使用技巧和使用细节、单例模式-懒汉式、单例模式-饿汉式【3】
java·javascript·后端·单例模式
一只月月鸟呀28 分钟前
HTML中数字和字母不换行显示
前端·html·css3
天下代码客1 小时前
【八股】介绍Promise(ES6引入)
前端·ecmascript·es6
lb29171 小时前
CSS 3D变换,transform:translateZ()
前端·css·3d
啊阿狸不会拉杆1 小时前
第二十二章:Python-NLTK库:自然语言处理
前端·python·自然语言处理
萧寂1731 小时前
html实现手势密码
前端·css·html