GithubHelp home page GithubHelp logo

learn-vue's People

Contributors

icesz avatar

Watchers

 avatar

learn-vue's Issues

修改意见

整体运行没有什么大问题~ 所以我们来聊聊实现上的细节吧~

命名

那些加减乘除的符号实际上你可以命名为 operator (操作符)

那个运算结果的方法不应该叫做 add,应该叫做 calculate (运算)

错误提示

我建议你搞一个单独的 div 用来显示错误的,而不是 alert 出来,因为好烦hhhhhh,类似于

{
    data:{
        errorText:"",
    },
    methods:{
        someMethod(){
            if(somethingWrong){
                this.errorText = "put some error text here";
            }
        }
    }
}

if 嵌套太深

if 嵌套太深不太方便阅读,后期改起来也比较麻烦。
你可以改成类似于这样:

function someMethod(){
    // 判断xxxxx
    if(somethingWrong){
        this.errorText = "put some error text here";
        return;
    }
    // 判断xxxxx
    if(somethingElseWrong){
        this.errorText = "put some error text here";
        return;
    }
}

判断空值

其实你只是判断了输入的内容等不等于空字符串,如果我输入的内容是一个空格,那就有问题了。

判断时加上 trim() 方法是一个好习惯

if(this.numOne.trim()===""){
//....
}

建议不要使用 eval

在不得已的情况下不要使用 eval 方法,非常不安全。虽然你的做法和用法都没有错。
建议使用 switch

switch(this.currentOperator){
    case "+":
        this.result = Number(this.numOne)+Number(this.numTwo);
        break;
    case "-":
        // ...其余的
}

进阶

期待你阅读完 Vue 的文档之后,能够消灭掉你现在的键盘事件。

就是不使用任何事件也能计算显示出结果~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.