Fe-interview: [vue] 在.vue文件中style是必须的吗?那script是必须的吗?为什么?

Created on 22 Jun 2019  ·  18Comments  ·  Source: haizlin/fe-interview

[vue] 在.vue文件中style是必须的吗?那script是必须的吗?为什么?

vue

Most helpful comment

试验了下,在 .vue 文件中,template是必须的,而script与style都不是必须的。
如果没有 template,则 [Vue warn]: Failed to mount component: template or render function not defined.

All 18 comments

萌新试着回答....
都不是必须的
至于为啥...
我感觉其实都没有的话那就是一个静态网页

style 不是必须的,script 是必须的,而且必须要写上

export default {}

都不是必须的

都不是必须的,但最好写上,至少script要写上。一切都是模块,因此最后都是转成JavaScript形式。

都不是必须的
如果是普通组件那么只能是一个静态html
如果是函数式组件, 那么可以直接使用props等函数式组件属性
https://cn.vuejs.org/v2/guide/render-function.html#%E5%87%BD%E6%95%B0%E5%BC%8F%E7%BB%84%E4%BB%B6

style 不是必须的,script 是必须的,而且必须要写上

export default {}

可以不写的

试验了下,在 .vue 文件中,template是必须的,而script与style都不是必须的。
如果没有 template,则 [Vue warn]: Failed to mount component: template or render function not defined.

不是

.....萌新一瞧,你们到底谁说得对

都不是必须的吧

管他三七二十一 vue点回车就行了

都不是必须的

试验了下,在 .vue 文件中,template是必须的,而script与style都不是必须的。
如果没有 template,则 [Vue warn]: Failed to mount component: template or render function not defined.

提示说,在option上挂个render函数也可以,所以template也不是必须的。 可以这么说吧

我想知道有很多问题有什么意义呢

@HerryBin .vue文件也可以用作mixins使用,所以template并不是必须的。确切来讲,script | template

都不是必须的

都不是必须的

我想知道有很多问题有什么意义呢

显得面试官 高大上哈,牛呗

Was this page helpful?
0 / 5 - 0 ratings