File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 88 nextTick ,
99 renderToString ,
1010 ref ,
11- defineComponent
11+ defineComponent ,
12+ createApp
1213} from '@vue/runtime-test'
1314
1415describe ( 'api: options' , ( ) => {
@@ -105,6 +106,24 @@ describe('api: options', () => {
105106 expect ( serializeInner ( root ) ) . toBe ( `<div>2</div>` )
106107 } )
107108
109+ test ( 'component’s own methods have higher priority than global properties' , async ( ) => {
110+ const app = createApp ( {
111+ methods : {
112+ foo ( ) {
113+ return 'foo'
114+ }
115+ } ,
116+ render ( ) {
117+ return this . foo ( )
118+ }
119+ } )
120+ app . config . globalProperties . foo = ( ) => 'bar'
121+
122+ const root = nodeOps . createElement ( 'div' )
123+ app . mount ( root )
124+ expect ( serializeInner ( root ) ) . toBe ( `foo` )
125+ } )
126+
108127 test ( 'watch' , async ( ) => {
109128 function returnThis ( this : any ) {
110129 return this
Original file line number Diff line number Diff line change @@ -604,7 +604,17 @@ export function applyOptions(
604604 for ( const key in methods ) {
605605 const methodHandler = ( methods as MethodOptions ) [ key ]
606606 if ( isFunction ( methodHandler ) ) {
607- ctx [ key ] = methodHandler . bind ( publicThis )
607+ // In dev mode, we use the `createRenderContext` function to define methods to the proxy target,
608+ // and those are read-only but reconfigurable, so it needs to be redefined here
609+ if ( __DEV__ ) {
610+ Object . defineProperty ( ctx , key , {
611+ value : methodHandler . bind ( publicThis ) ,
612+ configurable : true ,
613+ enumerable : false
614+ } )
615+ } else {
616+ ctx [ key ] = methodHandler . bind ( publicThis )
617+ }
608618 if ( __DEV__ ) {
609619 checkDuplicateProperties ! ( OptionTypes . METHODS , key )
610620 }
You can’t perform that action at this time.
0 commit comments