简体   繁体   English

我可以使用HTML / CSS和javascript创建登录页面,然后在其中添加VUE吗?

[英]Can I create a login page with HTML/CSS and javascript and later add VUE to it?

For a school project I have to create a web based application for a library system where the librarian can login which takes them to a page where they can add/remove/edit books. 对于一个学校项目,我必须为图书馆系统创建一个基于Web的应用程序,图书馆管理员可以在其中登录,然后将他们带到一个可以添加/删除/编辑书的页面。 I am in charge of the front-end and I am using Javascript and must use Vue (mandatory). 我负责前端,并且正在使用Javascript,并且必须使用Vue(强制性)。 I am wondering if I can first make this with HTML/CSS and javascript, then later add VUE components to it. 我想知道是否可以先使用HTML / CSS和javascript,然后再向其中添加VUE组件。 Still really unsure about what javascript frameworks such as vue do. 仍然不确定诸如vue这样的javascript框架会做什么。 But I am learning javascript at the moment still. 但是我现在仍在学习javascript。 So want to add VUE later once done learning javascript basics. 因此,一旦学习完javascript基础知识后,便想添加VUE。 Or would this be starting all over again so I should use vue now? 还是会重新开始,所以我现在应该使用vue吗?

Thank You 谢谢

Opinions will vary on this question. 关于这个问题的意见会有所不同。 Undoubtedly, long term it will make you a better web programmer to understand exactly what vue.js or any other library is doing is doing behind the scenes. 无疑,从长远来看,它将使您成为一个更好的Web程序员,以准确了解vue.js或任何其他库在幕后所做的事情。 Because all of these libraries are ultimately written in vanilla JavaScript, and are just translating what you do into vanilla JavaScript. 因为所有这些库最终都是用vanilla JavaScript编写的,并且只是将您所做的工作转换为vanilla JavaScript。

However that being said, since you're just starting out and your class is requiring vue.js, I tend to think it might be better to just start with vue. 不管怎么说,由于您刚刚开始学习并且您的班级要求使用vue.js,因此我倾向于认为仅从vue开始可能会更好。 The two methods are different enough that learning the vanilla JavaScript way first won't necessarily help vue.js make more sense. 两种方法的差异足够大,以至于首先学习香草JavaScript方式并不一定有助于vue.js变得更有意义。

Eventually yes, it will help everything make more sense and will make you a much better web programmer than you would be without the vanilla JavaScript knowledge. 最终是的,与没有原始的JavaScript知识相比,它将使一切变得更有意义,并使您成为更好的Web程序员。 But IMHO short term it probably won't help. 但是恕我直言,短期内它可能无济于事。 In fact you might drown on information overload. 实际上,您可能会淹没在信息超载中。

Since a picture...er...code snippet is worth a thousand words, I created a very simple example of how vanilla JS might handle a form submission versus how vue.js would do it. 由于picture ... er ... code片段价值一千个单词,因此,我创建了一个非常简单的示例,说明了普通JS如何处理表单提交以及vue.js会如何处理。 I've tried to add comments in the vanilla JS to show where vue.js is doing the same thing. 我尝试在原始JS中添加注释,以显示vue.js在做什么。

vanilla: 香草:

<form id='login-form'>
    <input id="uname" />
    <input type="password" id="pwd" />
    <input type="submit" value="Login" id="login" />
</form>

<script>
    var form = document.getElementById('login-form');  // handled below by el: '#login-vue'
    form.addEventListener('submit', function (e) { //handled below by @submit.prevent='submit'
        var uname = document.getElementById('uname').value; //handled below by v-model='uname'
        var pwd = document.getElementById('pwd').value; //handled below by v-model='pwd'
        console.log("submit form", { uname, pwd });
        e.preventDefault(); // handled below by .prevent on the @submit
    });
</script>

vue.js: vue.js:

<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<form id='login-vue' @submit.prevent='submit'>
    <input v-model='uname' />
    <input type="password" v-model='pwd' />
    <input type="submit" value="Login" />
</form>
<script>
    var app = new Vue({
        el: '#login-vue',
        data: { uname: '', pwd: '' },
        methods: {
            submit: function (e) {
                console.log("submit form", { uname: this.uname, pwd: this.pwd });
            }
        }
    })
</script>

If in looking at these examples you think the vanilla really helps you understand the vue.js, then maybe you're right to start there. 如果在看这些示例时您认为香草确实有助于您理解vue.js,那么也许您就从这里开始。 If not, then you might want to just start with the vue.js. 如果不是,那么您可能只想从vue.js开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM